diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-03-10 17:56:03 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-03-10 17:56:03 +0000 |
commit | 0624d2a1ecc2c0e3b17076cde1ed9781700d8c72 (patch) | |
tree | b422b0c2a2fd9fb33ef88695b6f13b85a4e36b1c /llvm/lib/Analysis | |
parent | b52221e941474cdb9fe25808e1936601342ba6fc (diff) | |
download | bcm5719-llvm-0624d2a1ecc2c0e3b17076cde1ed9781700d8c72.tar.gz bcm5719-llvm-0624d2a1ecc2c0e3b17076cde1ed9781700d8c72.zip |
Make this transformation slightly less agressive and more correct.
The 'CmpInst::isFalseWhenEqual' function returns 'false' for values other than
simply equality. For instance, it returns 'false' for <= or >=. This isn't the
correct behavior for this transformation, which is checking for strict equality
and non-equality. It was causing the gcc.c-torture/execute/frame-address.c test
to fail because it would completely (and incorrectly) optimize a whole function
into a 'ret i32 0'.
llvm-svn: 152497
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index c024e9260b1..95fd48ee658 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1609,23 +1609,33 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, if (llvm::isKnownNonNull(LHSPtr) || llvm::isKnownNonNull(RHSPtr)) { // If both sides are different identified objects, they aren't equal // unless they're null. - if (LHSPtr != RHSPtr && llvm::isIdentifiedObject(RHSPtr)) - return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred)); + if (LHSPtr != RHSPtr && llvm::isIdentifiedObject(RHSPtr) && + (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::FCMP_UEQ)) + return ConstantInt::get(ITy, false); // A local identified object (alloca or noalias call) can't equal any // incoming argument, unless they're both null. - if (isa<Instruction>(LHSPtr) && isa<Argument>(RHSPtr)) - return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred)); + if (isa<Instruction>(LHSPtr) && isa<Argument>(RHSPtr) && + (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::FCMP_UEQ)) + return ConstantInt::get(ITy, false); } // Assume that the constant null is on the right. - if (llvm::isKnownNonNull(LHSPtr) && isa<ConstantPointerNull>(RHSPtr)) - return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred)); + if (llvm::isKnownNonNull(LHSPtr) && isa<ConstantPointerNull>(RHSPtr)) { + if (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::FCMP_UEQ) + return ConstantInt::get(ITy, false); + else if (Pred == CmpInst::ICMP_NE || Pred == CmpInst::FCMP_ONE) + return ConstantInt::get(ITy, true); + } } else if (isa<Argument>(LHSPtr)) { RHSPtr = RHSPtr->stripInBoundsOffsets(); // An alloca can't be equal to an argument. - if (isa<AllocaInst>(RHSPtr)) - return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred)); + if (isa<AllocaInst>(RHSPtr)) { + if (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::FCMP_UEQ) + return ConstantInt::get(ITy, false); + else if (Pred == CmpInst::ICMP_NE || Pred == CmpInst::FCMP_ONE) + return ConstantInt::get(ITy, true); + } } // If we are comparing with zero then try hard since this is a common case. |