================
@@ -1175,6 +1175,79 @@ static Instruction
*foldConstantIntoDotAccumulator(IntrinsicInst &II,
return IC.replaceOperand(II, AccIdx, NewAcc);
}
+// Check raw buffer access is OOB or not. For partial OOB access, just bail
out.
+static bool isRawBufferAccessDefinitelyOOB(const GCNSubtarget *ST, Value *Rsrc,
+ Value *OffsetV, Value *SOffsetV,
+ Value *AuxV, uint64_t Payload,
+ const DataLayout &DL) {
+ using OOBModel = GCNSubtarget::AMDGPUBufferOOBModel;
+ std::optional<OOBModel> Model = ST->getBufferOOBModel();
+ std::optional<unsigned> NumRecordsWidth =
+ ST->getBufferResourceNumRecordsWidth();
+ if (!Model || !NumRecordsWidth)
+ return false;
+
+ auto *AuxC = dyn_cast<ConstantInt>(AuxV);
+ if (!AuxC)
+ return false;
+
+ uint64_t Offset = computeKnownBits(OffsetV, DL).getMinValue().getZExtValue();
+ uint64_t SOffset =
+ computeKnownBits(SOffsetV, DL).getMinValue().getZExtValue();
+
+ uint64_t Aux = AuxC->getZExtValue();
+ if (Aux & AMDGPU::CPol::VOLATILE)
+ return false;
+
+ // The resource descriptor must also be a compile-time constant.
+ const APInt *StrideAP, *NumRecAP, *FlagsAP;
+ if (!match(Rsrc, m_Intrinsic<Intrinsic::amdgcn_make_buffer_rsrc>(
+ m_Value(), m_APInt(StrideAP), m_APInt(NumRecAP),
+ m_APInt(FlagsAP))))
+ return false;
+
+ uint64_t StrideRaw = StrideAP->getZExtValue();
+ uint64_t Stride = StrideRaw & 0x3fff;
+ uint64_t Flags = FlagsAP->getZExtValue();
+ uint64_t NumRecordsMask = maskTrailingOnes<uint64_t>(*NumRecordsWidth);
+ uint64_t NumRecords =
+ NumRecAP->zextOrTrunc(64).getZExtValue() & NumRecordsMask;
+
+ switch (*Model) {
+ case OOBModel::Gfx9:
+ case OOBModel::Gfx10: {
+ bool AddTid = (Flags >> 23) & 1;
+ bool Swizzle = AMDGPU::isGFX11Plus(*ST) ? (StrideRaw >> 14) != 0
+ : (StrideRaw >> 15) != 0;
+ if (AddTid || Swizzle)
+ return false;
+
+ uint64_t Bound = NumRecords > SOffset ? NumRecords - SOffset : 0;
----------------
PrasoonMishra wrote:
I've kept the explicit form since `NumRecords/SOffset` are `uint64_t` here.
Using `APInt::usub_sat` would add unnecessary conversions (wrapping to 64-bit
`APInt` and then unwrapping); ternary looks cleaner.
Added a comment to indicate saturating subtraction behavior.
https://github.com/llvm/llvm-project/pull/227402
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits