Skip to content

Commit 8b11de7

Browse files
authored
[AMDGPU][SDAG] Initial support for ISD::PTRADD (llvm#141725)
Enable generation of PTRADD SelectionDAG nodes for pointer arithmetic for SI, for now behind an internal CLI option. Also add basic patterns to match these nodes. Optimizations will come in follow-up PRs. Basic tests for SDAG codegen with PTRADD are in test/CodeGen/AMDGPU/ptradd-sdag.ll Only affects 64-bit address spaces for now, since the immediate use case only affects the flat address space. For SWDEV-516125.
1 parent a361a3d commit 8b11de7

File tree

4 files changed

+566
-0
lines changed

4 files changed

+566
-0
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ static cl::opt<bool> UseDivergentRegisterIndexing(
6161
cl::desc("Use indirect register addressing for divergent indexes"),
6262
cl::init(false));
6363

64+
// TODO: This option should be removed once we switch to always using PTRADD in
65+
// the SelectionDAG.
66+
static cl::opt<bool> UseSelectionDAGPTRADD(
67+
"amdgpu-use-sdag-ptradd", cl::Hidden,
68+
cl::desc("Generate ISD::PTRADD nodes for 64-bit pointer arithmetic in the "
69+
"SelectionDAG ISel"),
70+
cl::init(false));
71+
6472
static bool denormalModeIsFlushAllF32(const MachineFunction &MF) {
6573
const SIMachineFunctionInfo *Info = MF.getInfo<SIMachineFunctionInfo>();
6674
return Info->getMode().FP32Denormals == DenormalMode::getPreserveSign();
@@ -10457,6 +10465,11 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op,
1045710465
}
1045810466
}
1045910467

10468+
bool SITargetLowering::shouldPreservePtrArith(const Function &F,
10469+
EVT PtrVT) const {
10470+
return UseSelectionDAGPTRADD && PtrVT == MVT::i64;
10471+
}
10472+
1046010473
// The raw.(t)buffer and struct.(t)buffer intrinsics have two offset args:
1046110474
// offset (the offset that is included in bounds checking and swizzling, to be
1046210475
// split between the instruction's voffset and immoffset fields) and soffset

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ class SITargetLowering final : public AMDGPUTargetLowering {
260260

261261
bool shouldExpandVectorDynExt(SDNode *N) const;
262262

263+
bool shouldPreservePtrArith(const Function &F, EVT PtrVT) const override;
264+
263265
private:
264266
// Analyze a combined offset from an amdgcn_s_buffer_load intrinsic and store
265267
// the three offsets (voffset, soffset and instoffset) into the SDValue[3]

llvm/lib/Target/AMDGPU/SIInstructions.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,20 @@ def : GCNPat <
13761376
(i32 (V_MOV_B32_e32 (i32 0))), sub1)
13771377
>;
13781378

1379+
//===----------------------------------------------------------------------===//
1380+
// PTRADD Patterns
1381+
//===----------------------------------------------------------------------===//
1382+
1383+
// GlobalISel shouldn't generate 64-bit addition pseudos.
1384+
let GISelShouldIgnore = 1 in {
1385+
def : GCNPat<
1386+
(DivergentBinFrag<ptradd> i64:$src0, i64:$src1),
1387+
(V_ADD_U64_PSEUDO $src0, $src1)>;
1388+
def : GCNPat<
1389+
(UniformBinFrag<ptradd> i64:$src0, i64:$src1),
1390+
(S_ADD_U64_PSEUDO $src0, $src1)>;
1391+
}
1392+
13791393
/********** ============================================ **********/
13801394
/********** Extraction, Insertion, Building and Casting **********/
13811395
/********** ============================================ **********/

0 commit comments

Comments
 (0)