diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-12-17 06:07:04 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-12-17 06:07:04 +0000 |
commit | e67cae33e1c537247909b6fe7e7ba0e0a44f4dfd (patch) | |
tree | 0ef627d1a8672aba7a77222bcba7861c512a5a68 /llvm/lib/VMCore/ConstantFold.cpp | |
parent | 3dfff974eccd5421583576be2dd8924db501e325 (diff) | |
download | bcm5719-llvm-e67cae33e1c537247909b6fe7e7ba0e0a44f4dfd.tar.gz bcm5719-llvm-e67cae33e1c537247909b6fe7e7ba0e0a44f4dfd.zip |
Aggressively flip compare constant expressions where appropriate; constant
folding in particular expects null to be on the RHS.
llvm-svn: 91587
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index 7f713d15c67..2449739aaf5 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -1839,14 +1839,16 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, } } - if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) { + if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) || + (C1->isNullValue() && !C2->isNullValue())) { // If C2 is a constant expr and C1 isn't, flip them around and fold the // other way if possible. + // Also, if C1 is null and C2 isn't, flip them around. switch (pred) { case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_NE: // No change of predicate required. - return ConstantFoldCompareInstruction(Context, pred, C2, C1); + return ConstantExpr::getICmp(pred, C2, C1); case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_SLT: @@ -1858,7 +1860,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, case ICmpInst::ICMP_SGE: // Change the predicate as necessary to swap the operands. pred = ICmpInst::getSwappedPredicate((ICmpInst::Predicate)pred); - return ConstantFoldCompareInstruction(Context, pred, C2, C1); + return ConstantExpr::getICmp(pred, C2, C1); default: // These predicates cannot be flopped around. break; |