Skip to content

Commit 4ded2d0

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f35e9fa478e2' from llvm.org/main into next
2 parents 5c70639 + f35e9fa commit 4ded2d0

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

llvm/lib/IR/Value.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -747,34 +747,28 @@ const Value *Value::stripAndAccumulateConstantOffsets(
747747
// means when we construct GEPOffset, we need to use the size
748748
// of GEP's pointer type rather than the size of the original
749749
// pointer type.
750-
unsigned CurBitWidth = DL.getIndexTypeSizeInBits(V->getType());
751-
if (CurBitWidth == BitWidth) {
752-
if (!GEP->accumulateConstantOffset(DL, Offset, ExternalAnalysis))
753-
return V;
754-
} else {
755-
APInt GEPOffset(CurBitWidth, 0);
756-
if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis))
757-
return V;
750+
APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0);
751+
if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis))
752+
return V;
758753

759-
// Stop traversal if the pointer offset wouldn't fit in the bit-width
760-
// provided by the Offset argument. This can happen due to AddrSpaceCast
761-
// stripping.
762-
if (GEPOffset.getSignificantBits() > BitWidth)
763-
return V;
754+
// Stop traversal if the pointer offset wouldn't fit in the bit-width
755+
// provided by the Offset argument. This can happen due to AddrSpaceCast
756+
// stripping.
757+
if (GEPOffset.getSignificantBits() > BitWidth)
758+
return V;
764759

765-
// External Analysis can return a result higher/lower than the value
766-
// represents. We need to detect overflow/underflow.
767-
APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth);
768-
if (!ExternalAnalysis) {
769-
Offset += GEPOffsetST;
770-
} else {
771-
bool Overflow = false;
772-
APInt OldOffset = Offset;
773-
Offset = Offset.sadd_ov(GEPOffsetST, Overflow);
774-
if (Overflow) {
775-
Offset = OldOffset;
776-
return V;
777-
}
760+
// External Analysis can return a result higher/lower than the value
761+
// represents. We need to detect overflow/underflow.
762+
APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth);
763+
if (!ExternalAnalysis) {
764+
Offset += GEPOffsetST;
765+
} else {
766+
bool Overflow = false;
767+
APInt OldOffset = Offset;
768+
Offset = Offset.sadd_ov(GEPOffsetST, Overflow);
769+
if (Overflow) {
770+
Offset = OldOffset;
771+
return V;
778772
}
779773
}
780774
V = GEP->getPointerOperand();

0 commit comments

Comments
 (0)