@@ -621,22 +621,6 @@ static Value *rewriteGEPAsOffset(Value *Start, Value *Base,
621
621
return NewInsts[Start];
622
622
}
623
623
624
- // / Looks through GEPs in order to express the input Value as a constant
625
- // / indexed GEP. Returns a pair containing the GEPs Pointer and Index.
626
- static std::pair<Value *, APInt>
627
- getAsConstantIndexedAddress (Value *V, const DataLayout &DL) {
628
- APInt Offset = APInt (DL.getIndexTypeSizeInBits (V->getType ()), 0 );
629
- while (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
630
- // We accept only inbouds GEPs here to exclude the possibility of
631
- // overflow.
632
- if (!GEP->isInBounds () || !GEP->accumulateConstantOffset (DL, Offset))
633
- break ;
634
-
635
- V = GEP->getPointerOperand ();
636
- }
637
- return {V, Offset};
638
- }
639
-
640
624
// / Converts (CMP GEPLHS, RHS) if this change would make RHS a constant.
641
625
// / We can look through PHIs, GEPs and casts in order to determine a common base
642
626
// / between GEPLHS and RHS.
@@ -651,9 +635,14 @@ static Instruction *transformToIndexedCompare(GEPOperator *GEPLHS, Value *RHS,
651
635
if (!GEPLHS->hasAllConstantIndices ())
652
636
return nullptr ;
653
637
654
- Value *PtrBase;
655
- APInt Offset;
656
- std::tie (PtrBase, Offset) = getAsConstantIndexedAddress (GEPLHS, DL);
638
+ APInt Offset (DL.getIndexTypeSizeInBits (GEPLHS->getType ()), 0 );
639
+ Value *PtrBase =
640
+ GEPLHS->stripAndAccumulateConstantOffsets (DL, Offset,
641
+ /* AllowNonInbounds*/ false );
642
+
643
+ // Bail if we looked through addrspacecast.
644
+ if (PtrBase->getType () != GEPLHS->getType ())
645
+ return nullptr ;
657
646
658
647
// The set of nodes that will take part in this transformation.
659
648
SetVector<Value *> Nodes;
0 commit comments