@@ -786,7 +786,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
786786 return transformToIndexedCompare (GEPLHS, RHS, Cond, DL, *this );
787787 }
788788
789- bool GEPsInBounds = GEPLHS->isInBounds () && GEPRHS->isInBounds ();
789+ GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags () & GEPRHS->getNoWrapFlags ();
790790 if (GEPLHS->getNumOperands () == GEPRHS->getNumOperands () &&
791791 GEPLHS->getSourceElementType () == GEPRHS->getSourceElementType ()) {
792792 // If the GEPs only differ by one index, compare it.
@@ -814,15 +814,15 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
814814 return replaceInstUsesWith (I, // No comparison is needed here.
815815 ConstantInt::get (I.getType (), ICmpInst::isTrueWhenEqual (Cond)));
816816
817- else if (NumDifferences == 1 && GEPsInBounds ) {
817+ else if (NumDifferences == 1 && NW. hasNoUnsignedSignedWrap () ) {
818818 Value *LHSV = GEPLHS->getOperand (DiffOperand);
819819 Value *RHSV = GEPRHS->getOperand (DiffOperand);
820820 // Make sure we do a signed comparison here.
821821 return new ICmpInst (ICmpInst::getSignedPredicate (Cond), LHSV, RHSV);
822822 }
823823 }
824824
825- if (GEPsInBounds || CmpInst::isEquality (Cond)) {
825+ if (NW. hasNoUnsignedSignedWrap () || CmpInst::isEquality (Cond)) {
826826 // ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)
827827 Value *L = EmitGEPOffset (GEPLHS, /* RewriteGEP=*/ true );
828828 Value *R = EmitGEPOffset (GEPRHS, /* RewriteGEP=*/ true );
0 commit comments