diff options
author | Duncan Sands <baldrick@free.fr> | 2010-11-07 16:12:23 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2010-11-07 16:12:23 +0000 |
commit | 1ac7c9979a2d723ff4649ffad58df02732872a5f (patch) | |
tree | 76d668b4d76a61b22618b2b8d47ad89ecffea961 /lib/Analysis/InstructionSimplify.cpp | |
parent | e25e1ef48b029795fd03be13791e5d19834bd503 (diff) |
Fix a README item: when doing a comparison with the result
of a select instruction, see if doing the compare with the
true and false values of the select gives the same result.
If so, that can be used as the value of the comparison.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | lib/Analysis/InstructionSimplify.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index b49b4d0c6a..1955802cc6 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -252,8 +252,27 @@ Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, break; } } - - + + // 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 "icmp select(cond, TV, FV), RHS", analyse it. + // Does "icmp TV, RHS" simplify? + if (Value *TCmp = SimplifyICmpInst(Pred, SI->getTrueValue(), RHS, TD)) + // It does! Does "icmp FV, RHS" simplify? + if (Value *FCmp = SimplifyICmpInst(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; } |