@@ -2686,27 +2686,14 @@ static Constant *computePointerICmp(CmpPredicate Pred, Value *LHS, Value *RHS,
2686
2686
const DataLayout &DL = Q.DL ;
2687
2687
const TargetLibraryInfo *TLI = Q.TLI ;
2688
2688
2689
- // We can only fold certain predicates on pointer comparisons.
2690
- switch (Pred) {
2691
- default :
2689
+ // We fold equality and unsigned predicates on pointer comparisons, but forbid
2690
+ // signed predicates since a GEP with inbounds could cross the sign boundary.
2691
+ if ( CmpInst::isSigned (Pred))
2692
2692
return nullptr ;
2693
2693
2694
- // Equality comparisons are easy to fold.
2695
- case CmpInst::ICMP_EQ:
2696
- case CmpInst::ICMP_NE:
2697
- break ;
2698
-
2699
- // We can only handle unsigned relational comparisons because 'inbounds' on
2700
- // a GEP only protects against unsigned wrapping.
2701
- case CmpInst::ICMP_UGT:
2702
- case CmpInst::ICMP_UGE:
2703
- case CmpInst::ICMP_ULT:
2704
- case CmpInst::ICMP_ULE:
2705
- // However, we have to switch them to their signed variants to handle
2706
- // negative indices from the base pointer.
2707
- Pred = ICmpInst::getSignedPredicate (Pred);
2708
- break ;
2709
- }
2694
+ // We have to switch to a signed predicate to handle negative indices from
2695
+ // the base pointer.
2696
+ Pred = ICmpInst::getSignedPredicate (Pred);
2710
2697
2711
2698
// Strip off any constant offsets so that we can reason about them.
2712
2699
// It's tempting to use getUnderlyingObject or even just stripInBoundsOffsets
@@ -2730,7 +2717,7 @@ static Constant *computePointerICmp(CmpPredicate Pred, Value *LHS, Value *RHS,
2730
2717
ICmpInst::compare (LHSOffset, RHSOffset, Pred));
2731
2718
2732
2719
// Various optimizations for (in)equality comparisons.
2733
- if (Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE ) {
2720
+ if (ICmpInst::isEquality ( Pred) ) {
2734
2721
// Different non-empty allocations that exist at the same time have
2735
2722
// different addresses (if the program can tell). If the offsets are
2736
2723
// within the bounds of their allocations (and not one-past-the-end!
0 commit comments