[llvm] [DirectX] Clean up extra vectors when lowering to buffer store (PR #116721)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 09:46:49 PST 2024
================
@@ -531,23 +531,46 @@ class OpLowerer {
return make_error<StringError>(
"typedBufferStore data must be a vector of 4 elements",
inconvertibleErrorCode());
- Value *Data0 =
- IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, 0));
- Value *Data1 =
- IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, 1));
- Value *Data2 =
- IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, 2));
- Value *Data3 =
- IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, 3));
-
- std::array<Value *, 8> Args{Handle, Index0, Index1, Data0,
- Data1, Data2, Data3, Mask};
+
+ // Since we're post-scalarizer, we likely have a vector that's constructed
+ // solely for the argument of the store.
+ std::array<Value *, 4> DataElements{nullptr, nullptr, nullptr, nullptr};
+ auto *IEI = dyn_cast<InsertElementInst>(Data);
+ while (IEI) {
+ auto *IndexOp = dyn_cast<ConstantInt>(IEI->getOperand(2));
+ if (!IndexOp)
+ break;
+ size_t IndexVal = IndexOp->getZExtValue();
+ assert(IndexVal < 4 && "Too many elements for buffer store");
----------------
bogner wrote:
I don't think so, this is fairly likely to crash in a non-asserts build if it comes up anyways, and this is a fairly obvious place we'd need to update if we were to make such a change. Note that we'd have to expand into multiple calls to `dx.op.BufferStore` here if we were to support larger vectors in HLSL, so this isn't just some implementation detail we'd be likely to forget about.
https://github.com/llvm/llvm-project/pull/116721
More information about the llvm-commits
mailing list