@@ -1541,11 +1541,11 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
1541
1541
return std::nullopt;
1542
1542
}
1543
1543
1544
- std::optional<int > llvm::getPointersDiff (Type *ElemTyA, Value *PtrA,
1545
- Type *ElemTyB, Value *PtrB,
1546
- const DataLayout &DL,
1547
- ScalarEvolution &SE, bool StrictCheck ,
1548
- bool CheckType) {
1544
+ std::optional<int64_t > llvm::getPointersDiff (Type *ElemTyA, Value *PtrA,
1545
+ Type *ElemTyB, Value *PtrB,
1546
+ const DataLayout &DL,
1547
+ ScalarEvolution &SE,
1548
+ bool StrictCheck, bool CheckType) {
1549
1549
assert (PtrA && PtrB && " Expected non-nullptr pointers." );
1550
1550
1551
1551
// Make sure that A and B are different pointers.
@@ -1570,7 +1570,7 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
1570
1570
const Value *PtrB1 = PtrB->stripAndAccumulateConstantOffsets (
1571
1571
DL, OffsetB, /* AllowNonInbounds=*/ true );
1572
1572
1573
- int Val;
1573
+ std::optional< int64_t > Val;
1574
1574
if (PtrA1 == PtrB1) {
1575
1575
// Retrieve the address space again as pointer stripping now tracks through
1576
1576
// `addrspacecast`.
@@ -1585,7 +1585,7 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
1585
1585
OffsetB = OffsetB.sextOrTrunc (IdxWidth);
1586
1586
1587
1587
OffsetB -= OffsetA;
1588
- Val = OffsetB.getSExtValue ();
1588
+ Val = OffsetB.trySExtValue ();
1589
1589
} else {
1590
1590
// Otherwise compute the distance with SCEV between the base pointers.
1591
1591
const SCEV *PtrSCEVA = SE.getSCEV (PtrA);
@@ -1594,10 +1594,14 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
1594
1594
SE.computeConstantDifference (PtrSCEVB, PtrSCEVA);
1595
1595
if (!Diff)
1596
1596
return std::nullopt;
1597
- Val = Diff->getSExtValue ();
1597
+ Val = Diff->trySExtValue ();
1598
1598
}
1599
- int Size = DL.getTypeStoreSize (ElemTyA);
1600
- int Dist = Val / Size;
1599
+
1600
+ if (!Val)
1601
+ return std::nullopt;
1602
+
1603
+ int64_t Size = DL.getTypeStoreSize (ElemTyA);
1604
+ int64_t Dist = *Val / Size;
1601
1605
1602
1606
// Ensure that the calculated distance matches the type-based one after all
1603
1607
// the bitcasts removal in the provided pointers.
@@ -1616,14 +1620,15 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
1616
1620
// first pointer in the array.
1617
1621
Value *Ptr0 = VL[0 ];
1618
1622
1619
- using DistOrdPair = std::pair<int64_t , int >;
1623
+ using DistOrdPair = std::pair<int64_t , unsigned >;
1620
1624
auto Compare = llvm::less_first ();
1621
1625
std::set<DistOrdPair, decltype (Compare)> Offsets (Compare);
1622
1626
Offsets.emplace (0 , 0 );
1623
1627
bool IsConsecutive = true ;
1624
1628
for (auto [Idx, Ptr] : drop_begin (enumerate(VL))) {
1625
- std::optional<int > Diff = getPointersDiff (ElemTy, Ptr0, ElemTy, Ptr, DL, SE,
1626
- /* StrictCheck=*/ true );
1629
+ std::optional<int64_t > Diff =
1630
+ getPointersDiff (ElemTy, Ptr0, ElemTy, Ptr, DL, SE,
1631
+ /* StrictCheck=*/ true );
1627
1632
if (!Diff)
1628
1633
return false ;
1629
1634
@@ -1654,7 +1659,7 @@ bool llvm::isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL,
1654
1659
return false ;
1655
1660
Type *ElemTyA = getLoadStoreType (A);
1656
1661
Type *ElemTyB = getLoadStoreType (B);
1657
- std::optional<int > Diff =
1662
+ std::optional<int64_t > Diff =
1658
1663
getPointersDiff (ElemTyA, PtrA, ElemTyB, PtrB, DL, SE,
1659
1664
/* StrictCheck=*/ true , CheckType);
1660
1665
return Diff && *Diff == 1 ;
0 commit comments