@@ -747,28 +747,34 @@ const Value *Value::stripAndAccumulateConstantOffsets(
747
747
// means when we construct GEPOffset, we need to use the size
748
748
// of GEP's pointer type rather than the size of the original
749
749
// pointer type.
750
- APInt GEPOffset (DL.getIndexTypeSizeInBits (V->getType ()), 0 );
751
- if (!GEP->accumulateConstantOffset (DL, GEPOffset, ExternalAnalysis))
752
- return V;
753
-
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;
759
-
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;
750
+ unsigned CurBitWidth = DL.getIndexTypeSizeInBits (V->getType ());
751
+ if (CurBitWidth == BitWidth) {
752
+ if (!GEP->accumulateConstantOffset (DL, Offset, ExternalAnalysis))
753
+ return V;
765
754
} else {
766
- bool Overflow = false ;
767
- APInt OldOffset = Offset;
768
- Offset = Offset.sadd_ov (GEPOffsetST, Overflow);
769
- if (Overflow) {
770
- Offset = OldOffset;
755
+ APInt GEPOffset (CurBitWidth, 0 );
756
+ if (!GEP->accumulateConstantOffset (DL, GEPOffset, ExternalAnalysis))
757
+ return V;
758
+
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)
771
763
return V;
764
+
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
+ }
772
778
}
773
779
}
774
780
V = GEP->getPointerOperand ();
0 commit comments