[llvm-commits] [llvm] r122332 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll
Duncan Sands
baldrick at free.fr
Tue Dec 21 07:03:43 PST 2010
Author: baldrick
Date: Tue Dec 21 09:03:43 2010
New Revision: 122332
URL: http://llvm.org/viewvc/llvm-project?rev=122332&view=rev
Log:
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.
Added:
llvm/trunk/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=122332&r1=122331&r2=122332&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Dec 21 09:03:43 2010
@@ -492,7 +492,8 @@
/// 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 @@
/// 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 @@
/// 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,
Added: llvm/trunk/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll?rev=122332&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll (added)
+++ llvm/trunk/test/Transforms/InstSimplify/2010-12-20-I1Arithmetic.ll Tue Dec 21 09:03:43 2010
@@ -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
+}
More information about the llvm-commits
mailing list