@@ -786,7 +786,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
786
786
return transformToIndexedCompare (GEPLHS, RHS, Cond, DL, *this );
787
787
}
788
788
789
- bool GEPsInBounds = GEPLHS->isInBounds () && GEPRHS->isInBounds ();
789
+ GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags () & GEPRHS->getNoWrapFlags ();
790
790
if (GEPLHS->getNumOperands () == GEPRHS->getNumOperands () &&
791
791
GEPLHS->getSourceElementType () == GEPRHS->getSourceElementType ()) {
792
792
// If the GEPs only differ by one index, compare it.
@@ -814,15 +814,15 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
814
814
return replaceInstUsesWith (I, // No comparison is needed here.
815
815
ConstantInt::get (I.getType (), ICmpInst::isTrueWhenEqual (Cond)));
816
816
817
- else if (NumDifferences == 1 && GEPsInBounds ) {
817
+ else if (NumDifferences == 1 && NW. hasNoUnsignedSignedWrap () ) {
818
818
Value *LHSV = GEPLHS->getOperand (DiffOperand);
819
819
Value *RHSV = GEPRHS->getOperand (DiffOperand);
820
820
// Make sure we do a signed comparison here.
821
821
return new ICmpInst (ICmpInst::getSignedPredicate (Cond), LHSV, RHSV);
822
822
}
823
823
}
824
824
825
- if (GEPsInBounds || CmpInst::isEquality (Cond)) {
825
+ if (NW. hasNoUnsignedSignedWrap () || CmpInst::isEquality (Cond)) {
826
826
// ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)
827
827
Value *L = EmitGEPOffset (GEPLHS, /* RewriteGEP=*/ true );
828
828
Value *R = EmitGEPOffset (GEPRHS, /* RewriteGEP=*/ true );
0 commit comments