aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-17 02:23:02 +0000
committerChris Lattner <sabre@nondot.org>2011-02-17 02:23:02 +0000
commit41429e3f1e4d72ee4f7d4df786b5b0c87405f5b0 (patch)
treeb84c775e728c3187f9450e611f2b6115eef0a6ef /lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent3e468e1efafe905b34f51517f7211ae62cbff480 (diff)
preserve NUW/NSW when transforming add x,x
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125711 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAddSub.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 4ff005e26c..89cc540da7 100644
--- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -147,8 +147,13 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
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)