aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-02-25 23:01:19 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-02-25 23:01:19 +0000
commit6fd3428afa46ace6712f0649bf4a7bd6799cc355 (patch)
tree0610507366cd0c856c8ba20cf26e1d6d5975c3b1 /lib/Analysis/InstructionSimplify.cpp
parent28e215ba63164f201292f8c77bf038b4282aa052 (diff)
Roll these back to r151448 until I figure out how they're breaking
MultiSource/Applications/lua. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151463 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp52
1 files changed, 10 insertions, 42 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 93f55684c2..37253f72cf 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -21,7 +21,6 @@
#include "llvm/Operator.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/InstructionSimplify.h"
-#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/ValueTracking.h"
@@ -1609,38 +1608,26 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
}
- // icmp <object*>, <object*/null> - Different identified objects have
+ // icmp <alloca*>, <global/alloca*/null> - Different stack variables have
// different addresses, and what's more the address of a stack variable is
- // never equal to another argument. Note that generalizing to the case where
- // LHS is a global variable address or null is pointless, since if both LHS
- // and RHS are constants then we already constant folded the compare, and if
- // only one of them is then we moved it to RHS already.
+ // never null or equal to the address of a global. Note that generalizing
+ // to the case where LHS is a global variable address or null is pointless,
+ // since if both LHS and RHS are constants then we already constant folded
+ // the compare, and if only one of them is then we moved it to RHS already.
Value *LHSPtr = LHS->stripPointerCasts();
Value *RHSPtr = RHS->stripPointerCasts();
if (LHSPtr == RHSPtr)
return ConstantInt::get(ITy, CmpInst::isTrueWhenEqual(Pred));
-
+
// Be more aggressive about stripping pointer adjustments when checking a
// comparison of an alloca address to another object. We can rip off all
// inbounds GEP operations, even if they are variable.
LHSPtr = stripPointerAdjustments(LHSPtr);
- if (llvm::isIdentifiedObject(LHSPtr)) {
+ if (isa<AllocaInst>(LHSPtr)) {
RHSPtr = stripPointerAdjustments(RHSPtr);
- 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));
-
- // 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)) ||
- (isa<Instruction>(RHSPtr) && isa<Argument>(LHSPtr)))
- return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
- }
-
- // Assume that the constant null is on the right.
- if (llvm::isKnownNonNull(LHSPtr) && isa<ConstantPointerNull>(RHSPtr))
+ if (LHSPtr != RHSPtr &&
+ (isa<GlobalValue>(RHSPtr) || isa<AllocaInst>(RHSPtr) ||
+ isa<ConstantPointerNull>(RHSPtr)))
return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
}
@@ -2252,25 +2239,6 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
return getFalse(ITy);
}
- // Simplify comparisons of GEPs.
- if (GetElementPtrInst *GLHS = dyn_cast<GetElementPtrInst>(LHS)) {
- if (GEPOperator *GRHS = dyn_cast<GEPOperator>(RHS)) {
- if (GLHS->getPointerOperand() == GRHS->getPointerOperand() &&
- GLHS->hasAllConstantIndices() && GRHS->hasAllConstantIndices()) {
- // The bases are equal and the indices are constant. Build a constant
- // expression GEP with the same indices and a null base pointer to see
- // what constant folding can make out of it.
- Constant *Null = Constant::getNullValue(GLHS->getPointerOperandType());
- SmallVector<Value *, 4> IndicesLHS(GLHS->idx_begin(), GLHS->idx_end());
- Constant *NewLHS = ConstantExpr::getGetElementPtr(Null, IndicesLHS);
-
- SmallVector<Value *, 4> IndicesRHS(GRHS->idx_begin(), GRHS->idx_end());
- Constant *NewRHS = ConstantExpr::getGetElementPtr(Null, IndicesRHS);
- return ConstantExpr::getICmp(Pred, NewLHS, NewRHS);
- }
- }
- }
-
// If the comparison is with the result of a select instruction, check whether
// comparing with either branch of the select always yields the same value.
if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))