[llvm-commits] [llvm] r57513 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/and-fcmp.ll
Evan Cheng
evan.cheng at apple.com
Tue Oct 14 11:13:38 PDT 2008
Author: evancheng
Date: Tue Oct 14 13:13:38 2008
New Revision: 57513
URL: http://llvm.org/viewvc/llvm-project?rev=57513&view=rev
Log:
- Somehow I forgot about one / une.
- Renumber fcmp predicates to match their icmp counterparts.
- Try swapping operands to expose more optimization opportunities.
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=57513&r1=57512&r2=57513&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Oct 14 13:13:38 2008
@@ -3124,14 +3124,16 @@
switch (CC) {
case FCmpInst::FCMP_ORD: isOrdered = true; return 0; // 000
case FCmpInst::FCMP_UNO: return 0; // 000
- case FCmpInst::FCMP_OEQ: isOrdered = true; return 1; // 001
- case FCmpInst::FCMP_UEQ: return 1; // 001
- case FCmpInst::FCMP_OGT: isOrdered = true; return 2; // 010
- case FCmpInst::FCMP_UGT: return 2; // 010
+ case FCmpInst::FCMP_OGT: isOrdered = true; return 1; // 001
+ case FCmpInst::FCMP_UGT: return 1; // 001
+ case FCmpInst::FCMP_OEQ: isOrdered = true; return 2; // 010
+ case FCmpInst::FCMP_UEQ: return 2; // 010
case FCmpInst::FCMP_OGE: isOrdered = true; return 3; // 011
case FCmpInst::FCMP_UGE: return 3; // 011
case FCmpInst::FCMP_OLT: isOrdered = true; return 4; // 100
case FCmpInst::FCMP_ULT: return 4; // 100
+ case FCmpInst::FCMP_ONE: isOrdered = true; return 5; // 101
+ case FCmpInst::FCMP_UNE: return 5; // 101
case FCmpInst::FCMP_OLE: isOrdered = true; return 6; // 110
case FCmpInst::FCMP_ULE: return 6; // 110
default:
@@ -3181,7 +3183,7 @@
static Value *getFCmpValue(bool isordered, unsigned code,
Value *LHS, Value *RHS) {
switch (code) {
- default: assert(0 && "Illegal ICmp code!");
+ default: assert(0 && "Illegal FCmp code!");
case 0:
if (isordered)
return new FCmpInst(FCmpInst::FCMP_ORD, LHS, RHS);
@@ -3189,14 +3191,14 @@
return new FCmpInst(FCmpInst::FCMP_UNO, LHS, RHS);
case 1:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OEQ, LHS, RHS);
+ return new FCmpInst(FCmpInst::FCMP_OGT, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UEQ, LHS, RHS);
+ return new FCmpInst(FCmpInst::FCMP_UGT, LHS, RHS);
case 2:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OGT, LHS, RHS);
+ return new FCmpInst(FCmpInst::FCMP_OEQ, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UGT, LHS, RHS);
+ return new FCmpInst(FCmpInst::FCMP_UEQ, LHS, RHS);
case 3:
if (isordered)
return new FCmpInst(FCmpInst::FCMP_OGE, LHS, RHS);
@@ -3209,6 +3211,11 @@
return new FCmpInst(FCmpInst::FCMP_ULT, LHS, RHS);
case 5:
if (isordered)
+ return new FCmpInst(FCmpInst::FCMP_ONE, LHS, RHS);
+ else
+ return new FCmpInst(FCmpInst::FCMP_UNE, LHS, RHS);
+ case 6:
+ if (isordered)
return new FCmpInst(FCmpInst::FCMP_OLE, LHS, RHS);
else
return new FCmpInst(FCmpInst::FCMP_ULE, LHS, RHS);
@@ -3973,6 +3980,11 @@
FCmpInst::Predicate Op0CC, Op1CC;
if (match(Op0, m_FCmp(Op0CC, m_Value(Op0LHS), m_Value(Op0RHS))) &&
match(Op1, m_FCmp(Op1CC, m_Value(Op1LHS), m_Value(Op1RHS)))) {
+ if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
+ // Swap RHS operands to match LHS.
+ Op1CC = FCmpInst::getSwappedPredicate(Op1CC);
+ std::swap(Op1LHS, Op1RHS);
+ }
if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
// Simplify (fcmp cc0 x, y) & (fcmp cc1 x, y).
if (Op0CC == Op1CC)
Modified: llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll?rev=57513&r1=57512&r2=57513&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll Tue Oct 14 13:13:38 2008
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep fcmp | count 2
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep fcmp | count 3
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep ret | grep 0
define zeroext i8 @t1(float %x, float %y) nounwind {
@@ -24,3 +24,11 @@
%retval = zext i1 %c to i8
ret i8 %retval
}
+
+define zeroext i8 @t4(float %x, float %y) nounwind {
+ %a = fcmp one float %y, %x
+ %b = fcmp ord float %x, %y
+ %c = and i1 %a, %b
+ %retval = zext i1 %c to i8
+ ret i8 %retval
+}
More information about the llvm-commits
mailing list