[llvm-commits] [llvm] r118379 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstCombine/select.ll
Duncan Sands
baldrick at free.fr
Sun Nov 7 08:46:25 PST 2010
Author: baldrick
Date: Sun Nov 7 10:46:25 2010
New Revision: 118379
URL: http://llvm.org/viewvc/llvm-project?rev=118379&view=rev
Log:
Add simplification of floating point comparisons with the result
of a select instruction, the same as already exists for integer
comparisons.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstCombine/select.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=118379&r1=118378&r2=118379&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Nov 7 10:46:25 2010
@@ -350,6 +350,26 @@
}
}
+ // 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;
}
Modified: llvm/trunk/test/Transforms/InstCombine/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=118379&r1=118378&r2=118379&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Sun Nov 7 10:46:25 2010
@@ -480,3 +480,11 @@
; CHECK: @test38
; CHECK: ret i1 false
}
+
+define i1 @test39(i1 %cond, double %x) {
+ %s = select i1 %cond, double %x, double 0x7FF0000000000000 ; RHS = +infty
+ %cmp = fcmp ule double %x, %s
+ ret i1 %cmp
+; CHECK: @test39
+; CHECK: ret i1 true
+}
More information about the llvm-commits
mailing list