diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-10-14 18:13:38 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-10-14 18:13:38 +0000 |
commit | 4990b257dd22ef5804fd93742ac5e8621c4d1608 (patch) | |
tree | b1658fc0d96d2be75b499e197668970ad3cf4d66 | |
parent | 552e3be775c3ed9ff79e3002b369c5267633f72b (diff) |
- Somehow I forgot about one / une.
- Renumber fcmp predicates to match their icmp counterparts.
- Try swapping operands to expose more optimization opportunities.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57513 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 30 | ||||
-rw-r--r-- | test/Transforms/InstCombine/and-fcmp.ll | 10 |
2 files changed, 30 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 391e61e074..a687dbde10 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3124,14 +3124,16 @@ static unsigned getFCmpCode(FCmpInst::Predicate CC, bool &isOrdered) { 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 *getICmpValue(bool sign, unsigned code, Value *LHS, Value *RHS) { 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 @@ static Value *getFCmpValue(bool isordered, unsigned code, 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 @@ static Value *getFCmpValue(bool isordered, unsigned code, 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 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { 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) diff --git a/test/Transforms/InstCombine/and-fcmp.ll b/test/Transforms/InstCombine/and-fcmp.ll index 9eecc21983..55efffa34f 100644 --- a/test/Transforms/InstCombine/and-fcmp.ll +++ b/test/Transforms/InstCombine/and-fcmp.ll @@ -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 @@ define zeroext i8 @t3(float %x, float %y) nounwind { %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 +} |