@@ -465,14 +465,14 @@ static LinearExpression GetLinearExpression(
465
465
return Val;
466
466
}
467
467
468
- // / To ensure a pointer offset fits in an integer of size PointerSize
469
- // / (in bits) when that size is smaller than the maximum pointer size. This is
468
+ // / To ensure a pointer offset fits in an integer of size IndexSize
469
+ // / (in bits) when that size is smaller than the maximum index size. This is
470
470
// / an issue, for example, in particular for 32b pointers with negative indices
471
471
// / that rely on two's complement wrap-arounds for precise alias information
472
- // / where the maximum pointer size is 64b.
473
- static APInt adjustToPointerSize (const APInt &Offset, unsigned PointerSize ) {
474
- assert (PointerSize <= Offset.getBitWidth () && " Invalid PointerSize !" );
475
- unsigned ShiftBits = Offset.getBitWidth () - PointerSize ;
472
+ // / where the maximum index size is 64b.
473
+ static APInt adjustToIndexSize (const APInt &Offset, unsigned IndexSize ) {
474
+ assert (IndexSize <= Offset.getBitWidth () && " Invalid IndexSize !" );
475
+ unsigned ShiftBits = Offset.getBitWidth () - IndexSize ;
476
476
return (Offset << ShiftBits).ashr (ShiftBits);
477
477
}
478
478
@@ -549,9 +549,9 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
549
549
SearchTimes++;
550
550
const Instruction *CxtI = dyn_cast<Instruction>(V);
551
551
552
- unsigned MaxPointerSize = DL.getMaxPointerSizeInBits ();
552
+ unsigned MaxIndexSize = DL.getMaxIndexSizeInBits ();
553
553
DecomposedGEP Decomposed;
554
- Decomposed.Offset = APInt (MaxPointerSize , 0 );
554
+ Decomposed.Offset = APInt (MaxIndexSize , 0 );
555
555
do {
556
556
// See if this is a bitcast or GEP.
557
557
const Operator *Op = dyn_cast<Operator>(V);
@@ -620,7 +620,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
620
620
unsigned AS = GEPOp->getPointerAddressSpace ();
621
621
// Walk the indices of the GEP, accumulating them into BaseOff/VarIndices.
622
622
gep_type_iterator GTI = gep_type_begin (GEPOp);
623
- unsigned PointerSize = DL.getPointerSizeInBits (AS);
623
+ unsigned IndexSize = DL.getIndexSizeInBits (AS);
624
624
// Assume all GEP operands are constants until proven otherwise.
625
625
bool GepHasConstantOffset = true ;
626
626
for (User::const_op_iterator I = GEPOp->op_begin () + 1 , E = GEPOp->op_end ();
@@ -643,26 +643,26 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
643
643
continue ;
644
644
Decomposed.Offset +=
645
645
DL.getTypeAllocSize (GTI.getIndexedType ()).getFixedSize () *
646
- CIdx->getValue ().sextOrTrunc (MaxPointerSize );
646
+ CIdx->getValue ().sextOrTrunc (MaxIndexSize );
647
647
continue ;
648
648
}
649
649
650
650
GepHasConstantOffset = false ;
651
651
652
- // If the integer type is smaller than the pointer size, it is implicitly
653
- // sign extended to pointer size.
652
+ // If the integer type is smaller than the index size, it is implicitly
653
+ // sign extended or truncated to index size.
654
654
unsigned Width = Index->getType ()->getIntegerBitWidth ();
655
- unsigned SExtBits = PointerSize > Width ? PointerSize - Width : 0 ;
656
- unsigned TruncBits = PointerSize < Width ? Width - PointerSize : 0 ;
655
+ unsigned SExtBits = IndexSize > Width ? IndexSize - Width : 0 ;
656
+ unsigned TruncBits = IndexSize < Width ? Width - IndexSize : 0 ;
657
657
LinearExpression LE = GetLinearExpression (
658
658
CastedValue (Index, 0 , SExtBits, TruncBits), DL, 0 , AC, DT);
659
659
660
660
// Scale by the type size.
661
661
unsigned TypeSize =
662
662
DL.getTypeAllocSize (GTI.getIndexedType ()).getFixedSize ();
663
- LE = LE.mul (APInt (PointerSize , TypeSize), GEPOp->isInBounds ());
664
- Decomposed.Offset += LE.Offset .sextOrSelf (MaxPointerSize );
665
- APInt Scale = LE.Scale .sextOrSelf (MaxPointerSize );
663
+ LE = LE.mul (APInt (IndexSize , TypeSize), GEPOp->isInBounds ());
664
+ Decomposed.Offset += LE.Offset .sextOrSelf (MaxIndexSize );
665
+ APInt Scale = LE.Scale .sextOrSelf (MaxIndexSize );
666
666
667
667
// If we already had an occurrence of this index variable, merge this
668
668
// scale into it. For example, we want to handle:
@@ -678,8 +678,8 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
678
678
}
679
679
680
680
// Make sure that we have a scale that makes sense for this target's
681
- // pointer size.
682
- Scale = adjustToPointerSize (Scale, PointerSize );
681
+ // index size.
682
+ Scale = adjustToIndexSize (Scale, IndexSize );
683
683
684
684
if (!!Scale) {
685
685
VariableGEPIndex Entry = {LE.Val , Scale, CxtI, LE.IsNSW };
@@ -689,7 +689,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
689
689
690
690
// Take care of wrap-arounds
691
691
if (GepHasConstantOffset)
692
- Decomposed.Offset = adjustToPointerSize (Decomposed.Offset , PointerSize );
692
+ Decomposed.Offset = adjustToIndexSize (Decomposed.Offset , IndexSize );
693
693
694
694
// Analyze the base pointer next.
695
695
V = GEPOp->getOperand (0 );
@@ -1258,7 +1258,7 @@ AliasResult BasicAAResult::aliasGEP(
1258
1258
CR = Index.Val .evaluateWith (CR).sextOrTrunc (OffsetRange.getBitWidth ());
1259
1259
1260
1260
assert (OffsetRange.getBitWidth () == Scale.getBitWidth () &&
1261
- " Bit widths are normalized to MaxPointerSize " );
1261
+ " Bit widths are normalized to MaxIndexSize " );
1262
1262
if (Index.IsNSW )
1263
1263
OffsetRange = OffsetRange.add (CR.smul_sat (ConstantRange (Scale)));
1264
1264
else
0 commit comments