Skip to content

Commit 2d7b780

Browse files
committed
Early return loadValue if loading only one element
1 parent 85148e3 commit 2d7b780

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

llvm/lib/Target/DirectX/DXILCBufferAccess.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ struct CBufferResource {
143143
Value *Result = nullptr;
144144
unsigned int Remaining =
145145
((DL.getTypeSizeInBits(Ty) / 8) / Intrin.EltSize) - 1;
146+
146147
if (Remaining == 0) {
147148
// We only have a single element, so we're done.
148149
Result = Elt;
@@ -154,30 +155,30 @@ struct CBufferResource {
154155
Result = Builder.CreateInsertElement(PoisonValue::get(VT), Result,
155156
Builder.getInt32(0), Name);
156157
}
157-
} else {
158-
// Walk each element and extract it, wrapping to new rows as needed.
159-
SmallVector<Value *> Extracts{Elt};
160-
while (Remaining--) {
161-
CurrentIndex %= Intrin.NumElts;
162-
163-
if (CurrentIndex == 0)
164-
CBufLoad = Builder.CreateIntrinsic(
165-
Intrin.RetTy, Intrin.IID,
166-
{Handle, ConstantInt::get(Builder.getInt32Ty(), ++CurrentRow)},
167-
nullptr, Name + ".load");
168-
169-
Extracts.push_back(Builder.CreateExtractValue(
170-
CBufLoad, {CurrentIndex++}, Name + ".extract"));
171-
}
158+
return Result;
159+
}
160+
161+
// Walk each element and extract it, wrapping to new rows as needed.
162+
SmallVector<Value *> Extracts{Elt};
163+
while (Remaining--) {
164+
CurrentIndex %= Intrin.NumElts;
165+
166+
if (CurrentIndex == 0)
167+
CBufLoad = Builder.CreateIntrinsic(
168+
Intrin.RetTy, Intrin.IID,
169+
{Handle, ConstantInt::get(Builder.getInt32Ty(), ++CurrentRow)},
170+
nullptr, Name + ".load");
172171

173-
// Finally, we build up the original loaded value.
174-
Result = PoisonValue::get(Ty);
175-
for (int I = 0, E = Extracts.size(); I < E; ++I)
176-
Result = Builder.CreateInsertElement(Result, Extracts[I],
177-
Builder.getInt32(I),
178-
Name + formatv(".upto{}", I));
172+
Extracts.push_back(Builder.CreateExtractValue(
173+
CBufLoad, {CurrentIndex++}, Name + ".extract"));
179174
}
180175

176+
// Finally, we build up the original loaded value.
177+
Result = PoisonValue::get(Ty);
178+
for (int I = 0, E = Extracts.size(); I < E; ++I)
179+
Result = Builder.CreateInsertElement(Result, Extracts[I],
180+
Builder.getInt32(I),
181+
Name + formatv(".upto{}", I));
181182
return Result;
182183
}
183184
};

0 commit comments

Comments
 (0)