Skip to content

Commit 0774000

Browse files
authored
[AMDGPULowerBufferFatPointers] Fix offset-only ptrtoint (#95543)
For ptrtoint that truncates to the offset only, the expansion generated a shift by the bit width, which is poison. Instead, we should return the offset directly. (The same problem exists for the constant expression case, but I plan to address that separately, and more comprehensively.)
1 parent 7ad12a7 commit 0774000

File tree

5 files changed

+2165
-1541
lines changed

5 files changed

+2165
-1541
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,20 +1435,22 @@ PtrParts SplitPtrStructs::visitPtrToIntInst(PtrToIntInst &PI) {
14351435
const DataLayout &DL = PI.getModule()->getDataLayout();
14361436
unsigned FatPtrWidth = DL.getPointerSizeInBits(AMDGPUAS::BUFFER_FAT_POINTER);
14371437

1438-
Value *RsrcInt;
1439-
if (Width <= BufferOffsetWidth)
1440-
RsrcInt = ConstantExpr::getIntegerValue(ResTy, APInt::getZero(Width));
1441-
else
1442-
RsrcInt = IRB.CreatePtrToInt(Rsrc, ResTy, PI.getName() + ".rsrc");
1443-
copyMetadata(RsrcInt, &PI);
1444-
1445-
Value *Shl = IRB.CreateShl(
1446-
RsrcInt,
1447-
ConstantExpr::getIntegerValue(ResTy, APInt(Width, BufferOffsetWidth)), "",
1448-
Width >= FatPtrWidth, Width > FatPtrWidth);
1449-
Value *OffCast =
1450-
IRB.CreateIntCast(Off, ResTy, /*isSigned=*/false, PI.getName() + ".off");
1451-
Value *Res = IRB.CreateOr(Shl, OffCast);
1438+
Value *Res;
1439+
if (Width <= BufferOffsetWidth) {
1440+
Res = IRB.CreateIntCast(Off, ResTy, /*isSigned=*/false,
1441+
PI.getName() + ".off");
1442+
} else {
1443+
Value *RsrcInt = IRB.CreatePtrToInt(Rsrc, ResTy, PI.getName() + ".rsrc");
1444+
Value *Shl = IRB.CreateShl(
1445+
RsrcInt,
1446+
ConstantExpr::getIntegerValue(ResTy, APInt(Width, BufferOffsetWidth)),
1447+
"", Width >= FatPtrWidth, Width > FatPtrWidth);
1448+
Value *OffCast = IRB.CreateIntCast(Off, ResTy, /*isSigned=*/false,
1449+
PI.getName() + ".off");
1450+
Res = IRB.CreateOr(Shl, OffCast);
1451+
}
1452+
1453+
copyMetadata(Res, &PI);
14521454
Res->takeName(&PI);
14531455
SplitUsers.insert(&PI);
14541456
PI.replaceAllUsesWith(Res);

0 commit comments

Comments
 (0)