aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Lamb <christopher.lamb@gmail.com>2007-12-18 20:30:28 +0000
committerChristopher Lamb <christopher.lamb@gmail.com>2007-12-18 20:30:28 +0000
commitfd8b1fd7f6cef30bfe102b1d940868c2744f4477 (patch)
tree1e986ff5c5dfc6583453566f1df0681fadac5035
parentfd52711675cb581e7672f131046e355a2b5ba167 (diff)
downloadexternal_llvm-fd8b1fd7f6cef30bfe102b1d940868c2744f4477.zip
external_llvm-fd8b1fd7f6cef30bfe102b1d940868c2744f4477.tar.gz
external_llvm-fd8b1fd7f6cef30bfe102b1d940868c2744f4477.tar.bz2
Remove an orthogonal transformation of the selection condition from my most recent submission.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45169 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp32
-rw-r--r--test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll11
2 files changed, 3 insertions, 40 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index d64afbb..dec298b 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2131,9 +2131,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
}
}
- // add (select (icmp 0 (sub m A)) X Y) A ->
- // add (select (icmp A m) X Y) A
- //
// add (select X 0 (sub n A)) A ->
// select X A n
{
@@ -2147,27 +2144,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
Value *TV = SI->getTrueValue();
Value *FV = SI->getFalseValue();
Value *A;
-
- // Can we fold the add into the argument of the compare?
- Value *Cond = SI->getCondition();
- if (ICmpInst *IC = dyn_cast<ICmpInst>(Cond)) {
- Value *ICOp0 = IC->getOperand(0);
- Value *ICOp1 = IC->getOperand(1);
- ConstantInt *C3, *C4;
-
- // Check both arguments of the compare for a matching subtract.
- if (match(ICOp0, m_ConstantInt(C3)) && C3->getValue() == 0 &&
- match(ICOp1, m_Sub(m_ConstantInt(C4), m_Value(A))) &&
- A == Other) {
- // We managed to fold the add into the RHS of the select condition.
- Cond = new ICmpInst(IC->getPredicate(), A, C4, "asis", SI);
- } else if (match(ICOp1, m_ConstantInt(C3)) && C3->getValue() == 0 &&
- match(ICOp0, m_Sub(m_ConstantInt(C4), m_Value(A))) &&
- A == Other) {
- // We managed to fold the add into the LHS of the select condition.
- Cond = new ICmpInst(IC->getPredicate(), C4, A, "asis", SI);
- }
- }
// Can we fold the add into the argument of the select?
// We check both true and false select arguments for a matching subtract.
@@ -2177,17 +2153,13 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
A == Other) {
// We managed to fold the add into the true select value,
// picking up a simplified condition, if available.
- return new SelectInst(Cond, C2, A, "adselsub");
+ return new SelectInst(SI->getCondition(), C2, A);
} else if (match(TV, m_ConstantInt(C1)) && C1->getValue() == 0 &&
match(FV, m_Sub(m_ConstantInt(C2), m_Value(A))) &&
A == Other) {
// We managed to fold the add into the false select value,
// picking up a simplified condition, if available.
- return new SelectInst(Cond, A, C2, "adselsub");
- } else if (Cond != SI->getCondition()) {
- // We only managed to fold the add into the select condition.
- SI->setOperand(0, Cond);
- Changed = true;
+ return new SelectInst(SI->getCondition(), A, C2);
}
}
}
diff --git a/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll b/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll
index 94d6c96..e44fc6f 100644
--- a/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll
+++ b/test/Transforms/InstCombine/2007-12-18-AddSelCmpSub.ll
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep {sub}
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {add} | count 1
define i32 @foo(i32 %a) {
entry:
@@ -19,15 +19,6 @@ entry:
ret i32 %tmp12
}
-define i32 @baz(i32 %a) {
-entry:
- %tmp15 = sub i32 99, %a ; <i32> [#uses=1]
- %tmp16 = icmp slt i32 %tmp15, 0 ; <i1> [#uses=1]
- %smax = select i1 %tmp16, i32 0, i32 42 ; <i32> [#uses=1]
- %tmp12 = add i32 %smax, %a ; <i32> [#uses=1]
- ret i32 %tmp12
-}
-
define i32 @fun(i32 %a) {
entry:
%tmp15 = sub i32 99, %a ; <i32> [#uses=1]