[llvm-commits] [llvm] r47241 - in /llvm/trunk: lib/Transforms/Scalar/Reassociate.cpp test/Transforms/Reassociate/subtest2.ll
Chris Lattner
sabre at nondot.org
Sun Feb 17 12:51:26 PST 2008
Author: lattner
Date: Sun Feb 17 14:51:26 2008
New Revision: 47241
URL: http://llvm.org/viewvc/llvm-project?rev=47241&view=rev
Log:
Split up subtracts into add+negate if they have a reassociable use or operand
that is also a subtract. This implements PR2047 and Transforms/Reassociate/subtest2.ll
Added:
llvm/trunk/test/Transforms/Reassociate/subtest2.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=47241&r1=47240&r2=47241&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Sun Feb 17 14:51:26 2008
@@ -399,13 +399,16 @@
return false;
// Don't bother to break this up unless either the LHS is an associable add or
- // if this is only used by one.
- if (isReassociableOp(Sub->getOperand(0), Instruction::Add))
+ // subtract or if this is only used by one.
+ if (isReassociableOp(Sub->getOperand(0), Instruction::Add) ||
+ isReassociableOp(Sub->getOperand(0), Instruction::Sub))
return true;
- if (isReassociableOp(Sub->getOperand(1), Instruction::Add))
+ if (isReassociableOp(Sub->getOperand(1), Instruction::Add) ||
+ isReassociableOp(Sub->getOperand(0), Instruction::Sub))
return true;
-
- if (Sub->hasOneUse() && isReassociableOp(Sub->use_back(), Instruction::Add))
+ if (Sub->hasOneUse() &&
+ (isReassociableOp(Sub->use_back(), Instruction::Add) ||
+ isReassociableOp(Sub->use_back(), Instruction::Sub)))
return true;
return false;
Added: llvm/trunk/test/Transforms/Reassociate/subtest2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/subtest2.ll?rev=47241&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/subtest2.ll (added)
+++ llvm/trunk/test/Transforms/Reassociate/subtest2.ll Sun Feb 17 14:51:26 2008
@@ -0,0 +1,13 @@
+; With sub reassociation, constant folding can eliminate the uses of %a.
+;
+; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | grep %a | count 1
+; PR2047
+
+define i32 @test(i32 %a, i32 %b, i32 %c) nounwind {
+entry:
+ %tmp3 = sub i32 %a, %b ; <i32> [#uses=1]
+ %tmp5 = sub i32 %tmp3, %c ; <i32> [#uses=1]
+ %tmp7 = sub i32 %tmp5, %a ; <i32> [#uses=1]
+ ret i32 %tmp7
+}
+
More information about the llvm-commits
mailing list