aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-12-21 15:03:43 +0000
committerDuncan Sands <baldrick@free.fr>2010-12-21 15:03:43 +0000
commit07f30fbd734069b80b90c6aeea0ae645ce3880c0 (patch)
treeab96462fb48d55a92b1c9b42f1d8cdf3a8411491
parent75d289ed6201e82718343d7a36d2a2fa082f6217 (diff)
downloadexternal_llvm-07f30fbd734069b80b90c6aeea0ae645ce3880c0.zip
external_llvm-07f30fbd734069b80b90c6aeea0ae645ce3880c0.tar.gz
external_llvm-07f30fbd734069b80b90c6aeea0ae645ce3880c0.tar.bz2
While I don't think any later transforms can fire, it seems cleaner to
not assume this (for example in case more transforms get added below it). Suggested by Frits van Bommel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122332 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/InstructionSimplify.cpp9
-rw-r--r--test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll22
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 157193d..f35d505 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -492,7 +492,8 @@ static Value *SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
/// i1 add -> xor.
if (MaxRecurse && Op0->getType()->isIntegerTy(1))
- return SimplifyXorInst(Op0, Op1, TD, DT, MaxRecurse-1);
+ if (Value *V = SimplifyXorInst(Op0, Op1, TD, DT, MaxRecurse-1))
+ return V;
// Try some generic simplifications for associative operations.
if (Value *V = SimplifyAssociativeBinOp(Instruction::Add, Op0, Op1, TD, DT,
@@ -555,7 +556,8 @@ static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
/// i1 sub -> xor.
if (MaxRecurse && Op0->getType()->isIntegerTy(1))
- return SimplifyXorInst(Op0, Op1, TD, DT, MaxRecurse-1);
+ if (Value *V = SimplifyXorInst(Op0, Op1, TD, DT, MaxRecurse-1))
+ return V;
// Mul distributes over Sub. Try some generic simplifications based on this.
if (Value *V = FactorizeBinOp(Instruction::Sub, Op0, Op1, Instruction::Mul,
@@ -608,7 +610,8 @@ static Value *SimplifyMulInst(Value *Op0, Value *Op1, const TargetData *TD,
/// i1 mul -> and.
if (MaxRecurse && Op0->getType()->isIntegerTy(1))
- return SimplifyAndInst(Op0, Op1, TD, DT, MaxRecurse-1);
+ if (Value *V = SimplifyAndInst(Op0, Op1, TD, DT, MaxRecurse-1))
+ return V;
// Try some generic simplifications for associative operations.
if (Value *V = SimplifyAssociativeBinOp(Instruction::Mul, Op0, Op1, TD, DT,
diff --git a/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll b/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll
new file mode 100644
index 0000000..8b795ea
--- /dev/null
+++ b/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll
@@ -0,0 +1,22 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i1 @add(i1 %x) {
+; CHECK: @add
+ %z = add i1 %x, %x
+ ret i1 %z
+; CHECK: ret i1 false
+}
+
+define i1 @sub(i1 %x) {
+; CHECK: @sub
+ %z = sub i1 false, %x
+ ret i1 %z
+; CHECK: ret i1 %x
+}
+
+define i1 @mul(i1 %x) {
+; CHECK: @mul
+ %z = mul i1 %x, %x
+ ret i1 %z
+; CHECK: ret i1 %x
+}