Skip to content

Commit f415a94

Browse files
author
Greg Roth
committed
Respond to more feedback
Separate out the load store lowering functions from the pass class in vector scalarization pass Calculate load size on scalar element rather than resret element type to get correct alignment on scalars instead of on the whole vector. Adjust various tests accordingly that depended on or used code generated with the incorrect alignment, which always just hit the max of 8. Change iteration through matching intrinsics in link scalarization pass Capitalize varibles according to coding standards Include and remove whitespace in tests.
1 parent 309a924 commit f415a94

5 files changed

Lines changed: 131 additions & 135 deletions

File tree

lib/HLSL/DxilScalarizeVectorLoadStores.cpp

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
using namespace llvm;
2525
using namespace hlsl;
2626

27-
class DxilScalarizeVectorLoadStores : public ModulePass {
28-
private:
29-
void scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL,
30-
CallInst *CI);
31-
void scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL,
32-
CallInst *CI);
27+
static void scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL,
28+
CallInst *CI);
29+
static void scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL,
30+
CallInst *CI);
3331

32+
class DxilScalarizeVectorLoadStores : public ModulePass {
3433
public:
3534
static char ID; // Pass identification, replacement for typeid
3635
explicit DxilScalarizeVectorLoadStores() : ModulePass(ID) {}
@@ -48,25 +47,22 @@ class DxilScalarizeVectorLoadStores : public ModulePass {
4847
bool Changed = false;
4948

5049
hlsl::OP *HlslOP = DM.GetOP();
51-
for (auto F = M.functions().begin(), E = M.functions().end(); F != E;) {
52-
Function *Func = &*(F++);
53-
DXIL::OpCodeClass OpClass;
54-
if (HlslOP->GetOpCodeClass(Func, OpClass)) {
55-
if (OpClass == DXIL::OpCodeClass::RawBufferVectorLoad) {
56-
for (auto U = Func->user_begin(), UE = Func->user_end(); U != UE;) {
57-
CallInst *CI = cast<CallInst>(*(U++));
58-
scalarizeVectorLoad(HlslOP, M.getDataLayout(), CI);
59-
Changed = true;
60-
}
61-
Func->eraseFromParent();
62-
} else if (OpClass == DXIL::OpCodeClass::RawBufferVectorStore) {
63-
for (auto U = Func->user_begin(), UE = Func->user_end(); U != UE;) {
64-
CallInst *CI = cast<CallInst>(*(U++));
65-
scalarizeVectorStore(HlslOP, M.getDataLayout(), CI);
66-
Changed = true;
67-
}
68-
Func->eraseFromParent();
69-
}
50+
for (auto FIt : HlslOP->GetOpFuncList(DXIL::OpCode::RawBufferVectorLoad)) {
51+
Function *Func = FIt.second;
52+
if (!Func) continue;
53+
for (auto U = Func->user_begin(), UE = Func->user_end(); U != UE;) {
54+
CallInst *CI = cast<CallInst>(*(U++));
55+
scalarizeVectorLoad(HlslOP, M.getDataLayout(), CI);
56+
Changed = true;
57+
}
58+
}
59+
for (auto FIt : HlslOP->GetOpFuncList(DXIL::OpCode::RawBufferVectorStore)) {
60+
Function *Func = FIt.second;
61+
if (!Func) continue;
62+
for (auto U = Func->user_begin(), UE = Func->user_end(); U != UE;) {
63+
CallInst *CI = cast<CallInst>(*(U++));
64+
scalarizeVectorStore(HlslOP, M.getDataLayout(), CI);
65+
Changed = true;
7066
}
7167
}
7268
return Changed;
@@ -90,16 +86,15 @@ static unsigned GetRawBufferMask(unsigned NumComponents) {
9086
return DXIL::kCompMask_All;
9187
}
9288

93-
void DxilScalarizeVectorLoadStores::scalarizeVectorLoad(hlsl::OP *HlslOP,
94-
const DataLayout &DL,
95-
CallInst *CI) {
89+
static void scalarizeVectorLoad(hlsl::OP *HlslOP, const DataLayout &DL,
90+
CallInst *CI) {
9691
IRBuilder<> Builder(CI);
9792
// Collect the information required to break this into scalar ops from args.
9893
DxilInst_RawBufferVectorLoad VecLd(CI);
9994
OP::OpCode OpCode = OP::OpCode::RawBufferLoad;
100-
llvm::Constant *opArg = Builder.getInt32((unsigned)OpCode);
95+
llvm::Constant *OpArg = Builder.getInt32((unsigned)OpCode);
10196
SmallVector<Value *, 10> Args;
102-
Args.emplace_back(opArg); // opcode @0.
97+
Args.emplace_back(OpArg); // opcode @0.
10398
Args.emplace_back(VecLd.get_buf()); // Resource handle @1.
10499
Args.emplace_back(VecLd.get_index()); // Index @2.
105100
Args.emplace_back(VecLd.get_elementOffset()); // Offset @3.
@@ -161,16 +156,15 @@ void DxilScalarizeVectorLoadStores::scalarizeVectorLoad(hlsl::OP *HlslOP,
161156
CI->eraseFromParent();
162157
}
163158

164-
void DxilScalarizeVectorLoadStores::scalarizeVectorStore(hlsl::OP *HlslOP,
165-
const DataLayout &DL,
166-
CallInst *CI) {
159+
static void scalarizeVectorStore(hlsl::OP *HlslOP, const DataLayout &DL,
160+
CallInst *CI) {
167161
IRBuilder<> Builder(CI);
168162
// Collect the information required to break this into scalar ops from args.
169163
DxilInst_RawBufferVectorStore VecSt(CI);
170164
OP::OpCode OpCode = OP::OpCode::RawBufferStore;
171-
llvm::Constant *opArg = Builder.getInt32((unsigned)OpCode);
165+
llvm::Constant *OpArg = Builder.getInt32((unsigned)OpCode);
172166
SmallVector<Value *, 10> Args;
173-
Args.emplace_back(opArg); // opcode @0.
167+
Args.emplace_back(OpArg); // opcode @0.
174168
Args.emplace_back(VecSt.get_uav()); // Resource handle @1.
175169
Args.emplace_back(VecSt.get_index()); // Index @2.
176170
Args.emplace_back(VecSt.get_elementOffset()); // Offset @3.

lib/HLSL/HLOperationLower.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4179,6 +4179,9 @@ Value *TranslateBufLoad(ResLoadHelper &helper, HLResource::Kind RK,
41794179
if (isBool || (is64 && isTyped))
41804180
EltTy = Builder.getInt32Ty();
41814181

4182+
// Calculate load size with the scalar memory element type.
4183+
unsigned LdSize = DL.getTypeAllocSize(EltTy);
4184+
41824185
// Adjust number of components as needed.
41834186
if (is64 && isTyped) {
41844187
// 64-bit types are stored as int32 pairs in typed buffers.
@@ -4190,7 +4193,6 @@ Value *TranslateBufLoad(ResLoadHelper &helper, HLResource::Kind RK,
41904193
NumComponents = 1;
41914194
}
41924195

4193-
unsigned LdSize = DL.getTypeAllocSize(EltTy);
41944196
SmallVector<Value *, 10> Args = GetBufLoadArgs(helper, RK, Builder, LdSize);
41954197

41964198
// Keep track of the first load for debug info migration.

tools/clang/test/CodeGenDXIL/hlsl/intrinsics/buffer-load-stores-sm69.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
// CHECK: %dx.types.ResRet.[[VTY:v[0-9]*[a-z][0-9][0-9]]] = type { <[[NUM:[0-9]*]] x [[TYPE:[a-z_0-9]*]]>, i32 }
1717

18-
ByteAddressBuffer RoByBuf : register(t1);
18+
ByteAddressBuffer RoByBuf : register(t1);
1919
RWByteAddressBuffer RwByBuf : register(u1);
2020

21-
StructuredBuffer< vector<TYPE, NUM> > RoStBuf : register(t2);
22-
RWStructuredBuffer< vector<TYPE, NUM> > RwStBuf : register(u2);
21+
StructuredBuffer<vector<TYPE, NUM> > RoStBuf : register(t2);
22+
RWStructuredBuffer<vector<TYPE, NUM> > RwStBuf : register(u2);
2323

2424
ConsumeStructuredBuffer<vector<TYPE, NUM> > CnStBuf : register(u4);
2525
AppendStructuredBuffer<vector<TYPE, NUM> > ApStBuf : register(u5);

0 commit comments

Comments
 (0)