[llvm-commits] [llvm] r125711 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineAddSub.cpp test/Transforms/InstCombine/add2.ll
Chris Lattner
sabre at nondot.org
Wed Feb 16 18:23:02 PST 2011
Author: lattner
Date: Wed Feb 16 20:23:02 2011
New Revision: 125711
URL: http://llvm.org/viewvc/llvm-project?rev=125711&view=rev
Log:
preserve NUW/NSW when transforming add x,x
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/add2.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=125711&r1=125710&r2=125711&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Wed Feb 16 20:23:02 2011
@@ -147,8 +147,13 @@
return BinaryOperator::CreateXor(LHS, RHS);
// X + X --> X << 1
- if (LHS == RHS && I.getType()->isIntegerTy())
- return BinaryOperator::CreateShl(LHS, ConstantInt::get(I.getType(), 1));
+ if (LHS == RHS && I.getType()->isIntegerTy()) {
+ BinaryOperator *New =
+ BinaryOperator::CreateShl(LHS, ConstantInt::get(I.getType(), 1));
+ New->setHasNoSignedWrap(I.hasNoSignedWrap());
+ New->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
+ return New;
+ }
// -A + B --> B - A
// -A + -B --> -(A + B)
Modified: llvm/trunk/test/Transforms/InstCombine/add2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add2.ll?rev=125711&r1=125710&r2=125711&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add2.ll Wed Feb 16 20:23:02 2011
@@ -33,3 +33,11 @@
; CHECK-NEXT: ret i32
}
+define i32 @test4(i32 %A) {
+ %B = add nuw i32 %A, %A
+ ret i32 %B
+; CHECK: @test4
+; CHECK-NEXT: %B = shl nuw i32 %A, 1
+; CHECK-NEXT: ret i32 %B
+}
+
More information about the llvm-commits
mailing list