aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-20 01:56:58 +0000
committerChris Lattner <sabre@nondot.org>2007-12-20 01:56:58 +0000
commitbf0c5f3e151e3aca581f687e1f2f00ac1dc9591e (patch)
treef1f12ce6db6e9903ea0174f8878a6856cb4d2ccb
parent22fa5d61491bc029563fce56923cc572cdafcbc7 (diff)
downloadexternal_llvm-bf0c5f3e151e3aca581f687e1f2f00ac1dc9591e.zip
external_llvm-bf0c5f3e151e3aca581f687e1f2f00ac1dc9591e.tar.gz
external_llvm-bf0c5f3e151e3aca581f687e1f2f00ac1dc9591e.tar.bz2
simplify this code with the new m_Zero() pattern. Make sure the select only
has a single use, and generalize it to not require N to be a constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45250 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index d7c4923..d9b4173 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2109,8 +2109,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
}
// add (cast *A to intptrtype) B ->
- // cast (GEP (cast *A to sbyte*) B) ->
- // intptrtype
+ // cast (GEP (cast *A to sbyte*) B) --> intptrtype
{
CastInst *CI = dyn_cast<CastInst>(LHS);
Value *Other = RHS;
@@ -2131,8 +2130,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
}
}
- // add (select X 0 (sub n A)) A ->
- // select X A n
+ // add (select X 0 (sub n A)) A --> select X A n
{
SelectInst *SI = dyn_cast<SelectInst>(LHS);
Value *Other = RHS;
@@ -2140,25 +2138,19 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
SI = dyn_cast<SelectInst>(RHS);
Other = LHS;
}
- if (SI) {
+ if (SI && SI->hasOneUse()) {
Value *TV = SI->getTrueValue();
Value *FV = SI->getFalseValue();
- Value *A;
+ Value *A, *N;
// Can we fold the add into the argument of the select?
// We check both true and false select arguments for a matching subtract.
- ConstantInt *C1, *C2;
- if (match(FV, m_ConstantInt(C1)) && C1->getValue() == 0 &&
- match(TV, m_Sub(m_ConstantInt(C2), m_Value(A))) &&
- A == Other) {
- // We managed to fold the add into the true select value.
- 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.
- return new SelectInst(SI->getCondition(), A, C2);
- }
+ if (match(FV, m_Zero()) && match(TV, m_Sub(m_Value(N), m_Value(A))) &&
+ A == Other) // Fold the add into the true select value.
+ return new SelectInst(SI->getCondition(), N, A);
+ if (match(TV, m_Zero()) && match(FV, m_Sub(m_Value(N), m_Value(A))) &&
+ A == Other) // Fold the add into the false select value.
+ return new SelectInst(SI->getCondition(), A, N);
}
}