aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp21
1 files changed, 8 insertions, 13 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp b/contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp
index 4775340b3438..60895d3ced1a 100644
--- a/contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/contrib/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2588,8 +2588,14 @@ computePointerICmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
// numerous hazards. AliasAnalysis and its utilities rely on special rules
// governing loads and stores which don't apply to icmps. Also, AliasAnalysis
// doesn't need to guarantee pointer inequality when it says NoAlias.
- Constant *LHSOffset = stripAndComputeConstantOffsets(DL, LHS);
- Constant *RHSOffset = stripAndComputeConstantOffsets(DL, RHS);
+
+ // Even if an non-inbounds GEP occurs along the path we can still optimize
+ // equality comparisons concerning the result.
+ bool AllowNonInbounds = ICmpInst::isEquality(Pred);
+ Constant *LHSOffset =
+ stripAndComputeConstantOffsets(DL, LHS, AllowNonInbounds);
+ Constant *RHSOffset =
+ stripAndComputeConstantOffsets(DL, RHS, AllowNonInbounds);
// If LHS and RHS are related via constant offsets to the same base
// value, we can replace it with an icmp which just compares the offsets.
@@ -2659,17 +2665,6 @@ computePointerICmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
!CmpInst::isTrueWhenEqual(Pred));
}
- // Even if an non-inbounds GEP occurs along the path we can still optimize
- // equality comparisons concerning the result. We avoid walking the whole
- // chain again by starting where the last calls to
- // stripAndComputeConstantOffsets left off and accumulate the offsets.
- Constant *LHSNoBound = stripAndComputeConstantOffsets(DL, LHS, true);
- Constant *RHSNoBound = stripAndComputeConstantOffsets(DL, RHS, true);
- if (LHS == RHS)
- return ConstantExpr::getICmp(Pred,
- ConstantExpr::getAdd(LHSOffset, LHSNoBound),
- ConstantExpr::getAdd(RHSOffset, RHSNoBound));
-
// If one side of the equality comparison must come from a noalias call
// (meaning a system memory allocation function), and the other side must
// come from a pointer that cannot overlap with dynamically-allocated