Repository navigation
[AMDGPU] Support TFE D16 format buffer loads on gfx8/10/11/12 - #211465
Conversation
|
@llvm/pr-subscribers-backend-amdgpu Author: Arseniy Obolenskiy (aobolensk) ChangesD16 format buffer loads have no TFE hardware variant 3 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
index 87e85bef7c701..8db7fd4d5541d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
@@ -6901,6 +6901,16 @@ bool AMDGPULegalizerInfo::legalizeBufferLoad(MachineInstr &MI,
return true;
}
+ if (IsFormat && !IsTyped && IsD16 && IsTFE) {
+ const Function &Fn = B.getMF().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoUnsupported(
+ Fn, "unsupported TFE D16 format buffer load", MI.getDebugLoc()));
+ B.buildUndef(Dst);
+ B.buildUndef(StatusDst);
+ MI.eraseFromParent();
+ return true;
+ }
+
std::tie(VOffset, ImmOffset) = splitBufferOffsets(B, VOffset);
unsigned Opc;
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 8156de7a24b01..c14a06aa9bc97 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -7835,6 +7835,15 @@ SDValue SITargetLowering::lowerIntrinsicLoad(MemSDNode *M, bool IsFormat,
assert(M->getNumValues() == 2 || M->getNumValues() == 3);
bool IsTFE = M->getNumValues() == 3;
+ if (IsD16 && IsTFE) {
+ DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
+ DAG.getMachineFunction().getFunction(),
+ "unsupported TFE D16 format buffer load", DL.getDebugLoc()));
+ return DAG.getMergeValues(
+ {DAG.getPOISON(LoadVT), DAG.getPOISON(MVT::i32), M->getOperand(0)},
+ DL);
+ }
+
unsigned Opc = IsFormat ? (IsTFE ? AMDGPUISD::BUFFER_LOAD_FORMAT_TFE
: AMDGPUISD::BUFFER_LOAD_FORMAT)
: IsTFE ? AMDGPUISD::BUFFER_LOAD_TFE
@@ -7855,12 +7864,15 @@ SDValue SITargetLowering::lowerIntrinsicLoad(MemSDNode *M, bool IsFormat,
}
EVT CastVT = getEquivalentMemType(*DAG.getContext(), LoadVT);
- SDVTList VTList = DAG.getVTList(CastVT, MVT::Other);
+ SDVTList VTList = IsTFE ? DAG.getVTList(CastVT, MVT::i32, MVT::Other)
+ : DAG.getVTList(CastVT, MVT::Other);
SDValue MemNode = getMemIntrinsicNode(Opc, DL, VTList, Ops, CastVT,
M->getMemOperand(), DAG);
- return DAG.getMergeValues(
- {DAG.getNode(ISD::BITCAST, DL, LoadVT, MemNode), MemNode.getValue(1)},
- DL);
+ SDValue Data = DAG.getNode(ISD::BITCAST, DL, LoadVT, MemNode);
+ if (IsTFE)
+ return DAG.getMergeValues(
+ {Data, MemNode.getValue(1), MemNode.getValue(2)}, DL);
+ return DAG.getMergeValues({Data, MemNode.getValue(1)}, DL);
}
static SDValue lowerICMPIntrinsic(const SITargetLowering &TLI, SDNode *N,
@@ -8407,8 +8419,8 @@ void SITargetLowering::ReplaceNodeResults(SDNode *N,
Results.push_back(Res.getOperand(I));
}
} else {
- Results.push_back(Res);
- Results.push_back(Res.getValue(1));
+ for (unsigned I = 0; I < N->getNumValues(); ++I)
+ Results.push_back(Res.getValue(I));
}
return;
}
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.struct.ptr.buffer.format.i8.xfail.ll b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.struct.ptr.buffer.format.i8.xfail.ll
index f5f8471f4dc1f..df137c5df98ea 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.struct.ptr.buffer.format.i8.xfail.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.struct.ptr.buffer.format.i8.xfail.ll
@@ -18,3 +18,26 @@ define amdgpu_ps void @store_i8(ptr addrspace(8) inreg %rsrc, i8 %data, i32 %ind
call void @llvm.amdgcn.struct.ptr.buffer.store.format.i8(i8 %data, ptr addrspace(8) %rsrc, i32 %index, i32 0, i32 0, i32 0)
ret void
}
+
+; A D16 buffer.load.format combined with TFE has no corresponding real
+; instruction (no TFE variant of the D16 format load opcodes exists in
+; hardware), so it must be refused instead of miscounting SDNode results.
+; CHECK: error: {{.*}}unsupported TFE D16 format buffer load
+define amdgpu_kernel void @load_v3i16_tfe(ptr addrspace(8) inreg %rsrc, ptr addrspace(1) %out, ptr addrspace(1) %status) {
+ %r = call {<3 x i16>, i32} @llvm.amdgcn.struct.ptr.buffer.load.format.sl_v3i16i32s(ptr addrspace(8) %rsrc, i32 0, i32 0, i32 0, i32 0)
+ %data = extractvalue {<3 x i16>, i32} %r, 0
+ %st = extractvalue {<3 x i16>, i32} %r, 1
+ store <3 x i16> %data, ptr addrspace(1) %out
+ store i32 %st, ptr addrspace(1) %status
+ ret void
+}
+
+; CHECK: error: {{.*}}unsupported TFE D16 format buffer load
+define amdgpu_kernel void @load_f16_tfe(ptr addrspace(8) inreg %rsrc, ptr addrspace(1) %out, ptr addrspace(1) %status) {
+ %r = call {half, i32} @llvm.amdgcn.struct.ptr.buffer.load.format.sl_f16i32s(ptr addrspace(8) %rsrc, i32 0, i32 0, i32 0, i32 0)
+ %data = extractvalue {half, i32} %r, 0
+ %st = extractvalue {half, i32} %r, 1
+ store half %data, ptr addrspace(1) %out
+ store i32 %st, ptr addrspace(1) %status
+ ret void
+}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
0287c2e to
2b51427
Compare
|
I see TFE+D16 supported for >=gfx10 (but I may be wrong). Should this check be target specific, if so? |
You're right, it's a gfx90a-specific hardware limitation... Narrowed the check to hasGFX90AInsts() and added codegen for D16+TFE format buffer loads on gfx8/gfx10/gfx11/gfx12, which do have real encodings |
| } | ||
|
|
||
| if (IsTFE) { | ||
| if (IsTFE && IsD16 && Ty.isVector()) { |
There was a problem hiding this comment.
This is a lot more than introducing a new error?
There was a problem hiding this comment.
Yes, renamed the PR
| return true; | ||
| } | ||
|
|
||
| if (IsFormat && !IsTyped && IsD16 && IsTFE && ST.hasGFX90AInsts()) { |
There was a problem hiding this comment.
This should not be a 90a insist check. I would also expect this to be caught by the target feature requirements on the intrinsic declaration
There was a problem hiding this comment.
TargetFeatures will gate on the whole Intrinsic::ID, but we have some non-TFE loads that are supposed to be allowed
There was a problem hiding this comment.
You can tag add a target tag for "has D16 TFE".
There was a problem hiding this comment.
TargetFeatures will gate on the whole Intrinsic::ID, but we have some non-TFE loads that are supposed to be allowed
That seems to make the custom intrinsic feature check necessary. I remember there is a PR somewhere.
There was a problem hiding this comment.
This should still be a !has-tfe-d16 check, not has90AInsts
|
Hi! This comment was generated using fuzz-fill, a new tool we're building to help improve LLVM test coverage by spotting lines introduced in a PR that don't yet appear to be exercised by the full test suite, including any tests added in this PR. Looking at PR head
If it makes sense, adding a regression test that validates these lines would be great. And if any of them are already tested and we missed it, we'd love to hear so we can improve the tool. Feel free to give us some feedback on whether this review was useful from your perspective. Thanks! |
| SDValue ZeroIdx = DAG.getVectorIdxConstant(0, DL); | ||
| SDValue ValueDWords = | ||
| NumValueDWords == 1 | ||
| ? DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32, Load, ZeroIdx) |
There was a problem hiding this comment.
There're buildels for this, no?
| return true; | ||
| } | ||
|
|
||
| if (IsFormat && !IsTyped && IsD16 && IsTFE && ST.hasGFX90AInsts()) { |
There was a problem hiding this comment.
This should be a has-TFE, not a not-90a
| bool hasPkMovB32() const { return HasGFX90AInsts; } | ||
|
|
||
| // Has a hardware encoding for TFE D16 format buffer loads. | ||
| bool hasBufferTFEFormatD16() const { return !HasGFX90AInsts; } |
There was a problem hiding this comment.
Should move this to a feature but I suppose that can be separate
There was a problem hiding this comment.
Let's do it in follow up
| Register PackedI16; | ||
| if (Unpacked) { | ||
| SmallVector<Register, 4> Repack; | ||
| for (Register R : LoadElts) | ||
| Repack.push_back(B.buildTrunc(LLT::integer(16), R).getReg(0)); | ||
| LLT RepackedTy = LLT::fixed_vector(NumValueDWords, LLT::integer(16)); | ||
| PackedI16 = B.buildMergeLikeInstr(RepackedTy, Repack).getReg(0); | ||
| } else { | ||
| Register Merged; | ||
| if (NumValueDWords == 1) { | ||
| Merged = LoadElts[0]; | ||
| } else { | ||
| LLT MergedTy = LLT::fixed_vector(NumValueDWords, I32); | ||
| Merged = B.buildMergeLikeInstr(MergedTy, LoadElts).getReg(0); | ||
| } | ||
| LLT PackedI16Ty = LLT::fixed_vector(NumValueDWords * 2, LLT::integer(16)); | ||
| PackedI16 = B.buildBitcast(PackedI16Ty, Merged).getReg(0); | ||
| } | ||
|
|
||
| LLT PackedI16Ty = B.getMRI()->getType(PackedI16); | ||
| LLT DstIntTy = Ty.changeElementType(LLT::integer(16)); | ||
| Register ValueI16 = PackedI16; | ||
| if (PackedI16Ty.getNumElements() != NumElts) { | ||
| ValueI16 = B.getMRI()->createGenericVirtualRegister(DstIntTy); | ||
| B.buildDeleteTrailingVectorElements(ValueI16, PackedI16); | ||
| } | ||
| if (EltTy.isFloat()) | ||
| B.buildBitcast(Dst, ValueI16); | ||
| else | ||
| B.buildCopy(Dst, ValueI16); |
There was a problem hiding this comment.
This is pretty ugly, and we have similar code in all of these functions
arsenm
left a comment
There was a problem hiding this comment.
The globalisel legalizer stuff is still ugly, we need better APIs
…11465) gfx90a has no hardware encoding for TFE D16 format buffer loads, so reject the combination there with a diagnostic. Other targets (gfx8/10/11/12) do have real encodings, so add codegen support for them instead of rejecting unconditionally.
…11465) gfx90a has no hardware encoding for TFE D16 format buffer loads, so reject the combination there with a diagnostic. Other targets (gfx8/10/11/12) do have real encodings, so add codegen support for them instead of rejecting unconditionally.
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/52603 Here is the relevant piece of the build log for the reference |
gfx90a has no hardware encoding for TFE D16 format buffer loads, so reject the combination there with a diagnostic. Other targets (gfx8/10/11/12) do have real encodings, so add codegen support for them instead of rejecting unconditionally.