-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[DirectX] Clean up extra vectors when lowering to buffer store #116721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we start support > 4 element vectors, are asserts like this going to bite us (ie hard to debug errors that don't show up in production builds?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| DataElements[IndexVal] = IEI->getOperand(1); | ||
| IEI = dyn_cast<InsertElementInst>(IEI->getOperand(0)); | ||
| } | ||
|
|
||
| // If for some reason we weren't able to forward the arguments from the | ||
| // scalarizer artifact, then we need to actually extract elements from the | ||
| // vector. | ||
| for (int I = 0, E = 4; I != E; ++I) | ||
| if (DataElements[I] == nullptr) | ||
| DataElements[I] = | ||
| IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, I)); | ||
|
|
||
| std::array<Value *, 8> Args{ | ||
| Handle, Index0, Index1, DataElements[0], | ||
| DataElements[1], DataElements[2], DataElements[3], Mask}; | ||
| Expected<CallInst *> OpCall = | ||
| OpBuilder.tryCreateOp(OpCode::BufferStore, Args, CI->getName()); | ||
| if (Error E = OpCall.takeError()) | ||
| return E; | ||
|
|
||
| CI->eraseFromParent(); | ||
| // Clean up any leftover `insertelement`s | ||
| IEI = dyn_cast<InsertElementInst>(Data); | ||
| while (IEI && IEI->use_empty()) { | ||
| InsertElementInst *Tmp = IEI; | ||
| IEI = dyn_cast<InsertElementInst>(IEI->getOperand(0)); | ||
| Tmp->eraseFromParent(); | ||
| } | ||
|
|
||
| return Error::success(); | ||
| }); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I feel that there's a "...so we can (do whatever this loop does)" missing from this comment, but that might just be my lack of familiarity with this sort of code speaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added "If so, just use the scalar values from before they're inserted into the temporary." to the comment.