summaryrefslogtreecommitdiff
path: root/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-01-11 00:25:45 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-01-11 00:25:45 +0000
commit53054785115a4e7b521251fd698b6b82ee2c5c8f (patch)
treefffcc85e4e2b1c4e1444a66ef5c707854877b1ab /lib/VMCore/ConstantFold.cpp
parent97149737f27457b0411e49af3e4539688e29848f (diff)
downloadllvm-53054785115a4e7b521251fd698b6b82ee2c5c8f.tar.gz
llvm-53054785115a4e7b521251fd698b6b82ee2c5c8f.tar.bz2
llvm-53054785115a4e7b521251fd698b6b82ee2c5c8f.tar.xz
Implement better constant folding of unordered FCMP predicates.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33063 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r--lib/VMCore/ConstantFold.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 6215bdd438..fffba1e6f9 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -1110,18 +1110,38 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
case FCmpInst::FCMP_FALSE: return ConstantBool::getFalse();
case FCmpInst::FCMP_TRUE: return ConstantBool::getTrue();
case FCmpInst::FCMP_UNO:
- case FCmpInst::FCMP_ORD: break; // Can't fold these
+ return ConstantBool::get(C1Val != C1Val || C2Val != C2Val);
+ case FCmpInst::FCMP_ORD:
+ return ConstantBool::get(C1Val == C1Val && C2Val == C2Val);
case FCmpInst::FCMP_UEQ:
+ if (C1Val != C1Val || C2Val != C2Val)
+ return ConstantBool::getTrue();
+ /* FALL THROUGH */
case FCmpInst::FCMP_OEQ: return ConstantBool::get(C1Val == C2Val);
- case FCmpInst::FCMP_ONE:
- case FCmpInst::FCMP_UNE: return ConstantBool::get(C1Val != C2Val);
- case FCmpInst::FCMP_OLT:
- case FCmpInst::FCMP_ULT: return ConstantBool::get(C1Val < C2Val);
+ case FCmpInst::FCMP_UNE:
+ if (C1Val != C1Val || C2Val != C2Val)
+ return ConstantBool::getTrue();
+ /* FALL THROUGH */
+ case FCmpInst::FCMP_ONE: return ConstantBool::get(C1Val != C2Val);
+ case FCmpInst::FCMP_ULT:
+ if (C1Val != C1Val || C2Val != C2Val)
+ return ConstantBool::getTrue();
+ /* FALL THROUGH */
+ case FCmpInst::FCMP_OLT: return ConstantBool::get(C1Val < C2Val);
case FCmpInst::FCMP_UGT:
+ if (C1Val != C1Val || C2Val != C2Val)
+ return ConstantBool::getTrue();
+ /* FALL THROUGH */
case FCmpInst::FCMP_OGT: return ConstantBool::get(C1Val > C2Val);
- case FCmpInst::FCMP_OLE:
- case FCmpInst::FCMP_ULE: return ConstantBool::get(C1Val <= C2Val);
+ case FCmpInst::FCMP_ULE:
+ if (C1Val != C1Val || C2Val != C2Val)
+ return ConstantBool::getTrue();
+ /* FALL THROUGH */
+ case FCmpInst::FCMP_OLE: return ConstantBool::get(C1Val <= C2Val);
case FCmpInst::FCMP_UGE:
+ if (C1Val != C1Val || C2Val != C2Val)
+ return ConstantBool::getTrue();
+ /* FALL THROUGH */
case FCmpInst::FCMP_OGE: return ConstantBool::get(C1Val >= C2Val);
}
} else if (const ConstantPacked *CP1 = dyn_cast<ConstantPacked>(C1)) {