forked from OSchip/llvm-project
InstCombine: mul to shl shouldn't preserve nsw
consider: mul i32 nsw %x, -2147483648 this instruction will not result in poison if %x is 1 however, if we transform this into: shl i32 nsw %x, 31 then we will be generating poison because we just shifted into the sign bit. This fixes PR21242. llvm-svn: 219566
This commit is contained in:
parent
686de24128
commit
3cac85e071
|
@ -176,8 +176,6 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
|||
if (NewCst) {
|
||||
BinaryOperator *Shl = BinaryOperator::CreateShl(NewOp, NewCst);
|
||||
|
||||
if (I.hasNoSignedWrap())
|
||||
Shl->setHasNoSignedWrap();
|
||||
if (I.hasNoUnsignedWrap())
|
||||
Shl->setHasNoUnsignedWrap();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ define void @fu1(i32 %parm) nounwind ssp {
|
|||
|
||||
; <label>:4 ; preds = %0
|
||||
%5 = load i32* %1, align 4
|
||||
%6 = mul nsw i32 %5, 8
|
||||
%6 = shl nsw i32 %5, 3
|
||||
; With "nsw", the alloca and its bitcast can be fused:
|
||||
%7 = add nsw i32 %6, 2048
|
||||
; CHECK: alloca double
|
||||
|
|
|
@ -219,7 +219,7 @@ define i16 @mul_add_to_mul_1(i16 %x) {
|
|||
%add2 = add nsw i16 %x, %mul1
|
||||
ret i16 %add2
|
||||
; CHECK-LABEL: @mul_add_to_mul_1(
|
||||
; CHECK-NEXT: %add2 = mul nsw i16 %x, 9
|
||||
; CHECK-NEXT: %add2 = mul i16 %x, 9
|
||||
; CHECK-NEXT: ret i16 %add2
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ define i16 @mul_add_to_mul_2(i16 %x) {
|
|||
%add2 = add nsw i16 %mul1, %x
|
||||
ret i16 %add2
|
||||
; CHECK-LABEL: @mul_add_to_mul_2(
|
||||
; CHECK-NEXT: %add2 = mul nsw i16 %x, 9
|
||||
; CHECK-NEXT: %add2 = mul i16 %x, 9
|
||||
; CHECK-NEXT: ret i16 %add2
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ define i16 @mul_add_to_mul_4(i16 %a) {
|
|||
%add = add nsw i16 %mul1, %mul2
|
||||
ret i16 %add
|
||||
; CHECK-LABEL: @mul_add_to_mul_4(
|
||||
; CHECK-NEXT: %add = mul nsw i16 %a, 9
|
||||
; CHECK-NEXT: %add = mul i16 %a, 9
|
||||
; CHECK-NEXT: ret i16 %add
|
||||
}
|
||||
|
||||
|
|
|
@ -810,7 +810,7 @@ define double @test71(double *%p, i64 %i) {
|
|||
|
||||
define double @test72(double *%p, i32 %i) {
|
||||
; CHECK-LABEL: @test72(
|
||||
%so = mul nsw i32 %i, 8
|
||||
%so = shl nsw i32 %i, 3
|
||||
%o = sext i32 %so to i64
|
||||
; CHECK-NEXT: sext i32 %i to i64
|
||||
%q = bitcast double* %p to i8*
|
||||
|
@ -825,7 +825,7 @@ define double @test72(double *%p, i32 %i) {
|
|||
|
||||
define double @test73(double *%p, i128 %i) {
|
||||
; CHECK-LABEL: @test73(
|
||||
%lo = mul nsw i128 %i, 8
|
||||
%lo = shl nsw i128 %i, 3
|
||||
%o = trunc i128 %lo to i64
|
||||
; CHECK-NEXT: trunc i128 %i to i64
|
||||
%q = bitcast double* %p to i8*
|
||||
|
@ -937,7 +937,7 @@ define %s @test79(%s *%p, i64 %i, i32 %j) {
|
|||
|
||||
define double @test80([100 x double]* %p, i32 %i) {
|
||||
; CHECK-LABEL: @test80(
|
||||
%tmp = mul nsw i32 %i, 8
|
||||
%tmp = shl nsw i32 %i, 3
|
||||
; CHECK-NEXT: sext i32 %i to i64
|
||||
%q = bitcast [100 x double]* %p to i8*
|
||||
%pp = getelementptr i8* %q, i32 %tmp
|
||||
|
@ -954,7 +954,7 @@ define double @test80_addrspacecast([100 x double] addrspace(1)* %p, i32 %i) {
|
|||
; CHECK-NEXT: getelementptr [100 x double] addrspace(1)* %p
|
||||
; CHECK-NEXT: load double addrspace(1)*
|
||||
; CHECK-NEXT: ret double
|
||||
%tmp = mul nsw i32 %i, 8
|
||||
%tmp = shl nsw i32 %i, 3
|
||||
%q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
|
||||
%pp = getelementptr i8 addrspace(2)* %q, i32 %tmp
|
||||
%r = addrspacecast i8 addrspace(2)* %pp to double addrspace(1)*
|
||||
|
@ -968,7 +968,7 @@ define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) {
|
|||
; CHECK-NEXT: addrspacecast double addrspace(1)*
|
||||
; CHECK-NEXT: load double addrspace(3)*
|
||||
; CHECK-NEXT: ret double
|
||||
%tmp = mul nsw i32 %i, 8
|
||||
%tmp = shl nsw i32 %i, 3
|
||||
%q = addrspacecast [100 x double] addrspace(1)* %p to i8 addrspace(2)*
|
||||
%pp = getelementptr i8 addrspace(2)* %q, i32 %tmp
|
||||
%r = addrspacecast i8 addrspace(2)* %pp to double addrspace(3)*
|
||||
|
@ -978,7 +978,7 @@ define double @test80_addrspacecast_2([100 x double] addrspace(1)* %p, i32 %i) {
|
|||
|
||||
define double @test80_as1([100 x double] addrspace(1)* %p, i16 %i) {
|
||||
; CHECK-LABEL: @test80_as1(
|
||||
%tmp = mul nsw i16 %i, 8
|
||||
%tmp = shl nsw i16 %i, 3
|
||||
; CHECK-NEXT: sext i16 %i to i32
|
||||
%q = bitcast [100 x double] addrspace(1)* %p to i8 addrspace(1)*
|
||||
%pp = getelementptr i8 addrspace(1)* %q, i16 %tmp
|
||||
|
|
|
@ -217,7 +217,7 @@ define i32 @test25(i32 %a) {
|
|||
%div = sdiv i32 %shl, 2
|
||||
ret i32 %div
|
||||
; CHECK-LABEL: @test25(
|
||||
; CHECK-NEXT: %div = shl nsw i32 %a, 1
|
||||
; CHECK-NEXT: %div = shl i32 %a, 1
|
||||
; CHECK-NEXT: ret i32 %div
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ define i32 @test26(i32 %a) {
|
|||
%div = sdiv i32 %mul, 3
|
||||
ret i32 %div
|
||||
; CHECK-LABEL: @test26(
|
||||
; CHECK-NEXT: %div = shl nsw i32 %a, 2
|
||||
; CHECK-NEXT: %div = shl i32 %a, 2
|
||||
; CHECK-NEXT: ret i32 %div
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue