[llvm] r235250 - [InstCombine] (mul nsw 1, INT_MIN) != (shl nsw 1, 31)
David Majnemer
david.majnemer at gmail.com
Fri Apr 17 21:41:30 PDT 2015
Author: majnemer
Date: Fri Apr 17 23:41:30 2015
New Revision: 235250
URL: http://llvm.org/viewvc/llvm-project?rev=235250&view=rev
Log:
[InstCombine] (mul nsw 1, INT_MIN) != (shl nsw 1, 31)
Multiplying INT_MIN by 1 doesn't trigger nsw. However, shifting 1 into
the sign bit *does* trigger nsw.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/mul.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=235250&r1=235249&r2=235250&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Fri Apr 17 23:41:30 2015
@@ -217,12 +217,16 @@ Instruction *InstCombiner::visitMul(Bina
NewCst = getLogBase2Vector(CV);
if (NewCst) {
+ unsigned Width = NewCst->getType()->getPrimitiveSizeInBits();
BinaryOperator *Shl = BinaryOperator::CreateShl(NewOp, NewCst);
if (I.hasNoUnsignedWrap())
Shl->setHasNoUnsignedWrap();
- if (I.hasNoSignedWrap() && NewCst->isNotMinSignedValue())
- Shl->setHasNoSignedWrap();
+ if (I.hasNoSignedWrap()) {
+ uint64_t V;
+ if (match(NewCst, m_ConstantInt(V)) && V != Width - 1)
+ Shl->setHasNoSignedWrap();
+ }
return Shl;
}
Modified: llvm/trunk/test/Transforms/InstCombine/mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mul.ll?rev=235250&r1=235249&r2=235250&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/mul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/mul.ll Fri Apr 17 23:41:30 2015
@@ -288,3 +288,19 @@ define i32 @test31(i32 %V) {
; CHECK: %[[mul:.*]] = shl i32 %V, zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32)
; CHECK-NEXT: ret i32 %[[mul]]
}
+
+define i32 @test32(i32 %X) {
+; CHECK-LABEL: @test32
+ %mul = mul nsw i32 %X, -2147483648
+ ret i32 %mul
+; CHECK: %[[shl:.*]] = shl i32 %X, 31
+; CHECK-NEXT: ret i32 %[[shl]]
+}
+
+define i32 @test33(i32 %X) {
+; CHECK-LABEL: @test33
+ %mul = mul nsw i32 %X, 1073741824
+; CHECK: %[[shl:.*]] = shl nsw i32 %X, 30
+; CHECK-NEXT: ret i32 %[[shl]]
+ ret i32 %mul
+}
More information about the llvm-commits
mailing list