diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -451,7 +451,8 @@ } } - Known = KnownBits::mul(Known, Known2); + bool SelfMultiply = Op0 == Op1; + Known = KnownBits::mul(Known, Known2, SelfMultiply); // Only make use of no-wrap flags if we failed to compute the sign bit // directly. This matters if the multiplication always overflows, in diff --git a/llvm/test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll b/llvm/test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll --- a/llvm/test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll +++ b/llvm/test/Analysis/ScalarEvolution/solve-quadratic-overflow.ll @@ -12,11 +12,11 @@ ; CHECK-NEXT: %v3 = mul i16 %v2, %v2 ; CHECK-NEXT: --> {1,+,3,+,2}<%b1> U: full-set S: full-set Exits: 0 LoopDispositions: { %b1: Computable } ; CHECK-NEXT: %v5 = phi i16 [ %v2, %b1 ] -; CHECK-NEXT: --> %v5 U: [-256,0) S: [-256,0) +; CHECK-NEXT: --> %v5 U: [-256,0) S: [-256,0) --> -256 U: [-256,-255) S: [-256,-255) ; CHECK-NEXT: %v6 = phi i16 [ %v3, %b1 ] -; CHECK-NEXT: --> %v6 U: full-set S: full-set +; CHECK-NEXT: --> %v6 U: [0,-2) S: [0,-2) --> 0 U: [0,1) S: [0,1) ; CHECK-NEXT: %v7 = sext i16 %v5 to i32 -; CHECK-NEXT: --> (sext i16 %v5 to i32) U: [-256,0) S: [-256,0) +; CHECK-NEXT: --> (sext i16 %v5 to i32) U: [-256,0) S: [-256,0) --> -256 U: [-256,-255) S: [-256,-255) ; CHECK-NEXT: Determining loop execution counts for: @f0 ; CHECK-NEXT: Loop %b1: backedge-taken count is 255 ; CHECK-NEXT: Loop %b1: max backedge-taken count is 255 diff --git a/llvm/test/Transforms/InstCombine/mul-masked-bits.ll b/llvm/test/Transforms/InstCombine/mul-masked-bits.ll --- a/llvm/test/Transforms/InstCombine/mul-masked-bits.ll +++ b/llvm/test/Transforms/InstCombine/mul-masked-bits.ll @@ -22,10 +22,7 @@ define i1 @PR48683(i32 %x) { ; CHECK-LABEL: @PR48683( -; CHECK-NEXT: [[A:%.*]] = mul i32 [[X:%.*]], [[X]] -; CHECK-NEXT: [[B:%.*]] = and i32 [[A]], 2 -; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[B]], 0 -; CHECK-NEXT: ret i1 [[C]] +; CHECK-NEXT: ret i1 false ; %a = mul i32 %x, %x %b = and i32 %a, 2 @@ -35,10 +32,7 @@ define <4 x i1> @PR48683_vec(<4 x i32> %x) { ; CHECK-LABEL: @PR48683_vec( -; CHECK-NEXT: [[A:%.*]] = mul <4 x i32> [[X:%.*]], [[X]] -; CHECK-NEXT: [[B:%.*]] = and <4 x i32> [[A]], -; CHECK-NEXT: [[C:%.*]] = icmp ne <4 x i32> [[B]], zeroinitializer -; CHECK-NEXT: ret <4 x i1> [[C]] +; CHECK-NEXT: ret <4 x i1> zeroinitializer ; %a = mul <4 x i32> %x, %x %b = and <4 x i32> %a,