summaryrefslogtreecommitdiff
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-11-07 16:46:25 +0000
committerDuncan Sands <baldrick@free.fr>2010-11-07 16:46:25 +0000
commit92826def593df7a422c7b07f09342febce81ddd3 (patch)
treed68e73f03c42ee7affc0c3c63aea892f59f5394e /lib/Analysis/InstructionSimplify.cpp
parent1ac7c9979a2d723ff4649ffad58df02732872a5f (diff)
downloadllvm-92826def593df7a422c7b07f09342febce81ddd3.tar.gz
llvm-92826def593df7a422c7b07f09342febce81ddd3.tar.bz2
llvm-92826def593df7a422c7b07f09342febce81ddd3.tar.xz
Add simplification of floating point comparisons with the result
of a select instruction, the same as already exists for integer comparisons. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118379 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 1955802cc6..66452a5d98 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -350,6 +350,26 @@ Value *llvm::SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
}
+ // If the comparison is with the result of a select instruction, check whether
+ // comparing with either branch of the select always yields the same value.
+ if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS)) {
+ // Make sure the select is on the LHS.
+ if (!isa<SelectInst>(LHS)) {
+ std::swap(LHS, RHS);
+ Pred = CmpInst::getSwappedPredicate(Pred);
+ }
+ SelectInst *SI = cast<SelectInst>(LHS);
+ // Now that we have "fcmp select(cond, TV, FV), RHS", analyse it.
+ // Does "fcmp TV, RHS" simplify?
+ if (Value *TCmp = SimplifyFCmpInst(Pred, SI->getTrueValue(), RHS, TD))
+ // It does! Does "fcmp FV, RHS" simplify?
+ if (Value *FCmp = SimplifyFCmpInst(Pred, SI->getFalseValue(), RHS, TD))
+ // It does! If they simplified to the same value, then use it as the
+ // result of the original comparison.
+ if (TCmp == FCmp)
+ return TCmp;
+ }
+
return 0;
}