Skip to content

Commit 53690ba

Browse files
committed
address pr comments
1 parent b020f5c commit 53690ba

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

llvm/lib/Target/DirectX/DXILLegalizePass.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void emitMemsetExpansion(IRBuilder<> &Builder, Value *Dst, Value *Val,
251251
ConstantInt *SizeCI,
252252
DenseMap<Value *, Value *> &ReplacedValues) {
253253
LLVMContext &Ctx = Builder.getContext();
254-
[[maybe_unused]] DataLayout DL =
254+
[[maybe_unused]] const DataLayout &DL =
255255
Builder.GetInsertBlock()->getModule()->getDataLayout();
256256
[[maybe_unused]] uint64_t OrigSize = SizeCI->getZExtValue();
257257

@@ -276,16 +276,18 @@ void emitMemsetExpansion(IRBuilder<> &Builder, Value *Dst, Value *Val,
276276
Value *TypedVal = Val;
277277

278278
if (Val->getType() != ElemTy) {
279-
// Note for i8 replacements if we know them we should use them.
280-
// Further if this is a constant ReplacedValues will return null
281-
// so we will stick to TypedVal = Val
282-
if (ReplacedValues[Val])
279+
if (ReplacedValues[Val]) {
280+
// Note for i8 replacements if we know them we should use them.
281+
// Further if this is a constant ReplacedValues will return null
282+
// so we will stick to TypedVal = Val
283283
TypedVal = ReplacedValues[Val];
284-
// This case Val is a ConstantInt so the cast folds away.
285-
// However if we don't do the cast the store below ends up being
286-
// an i8.
287-
else
284+
285+
} else {
286+
// This case Val is a ConstantInt so the cast folds away.
287+
// However if we don't do the cast the store below ends up being
288+
// an i8.
288289
TypedVal = Builder.CreateIntCast(Val, ElemTy, false);
290+
}
289291
}
290292

291293
for (uint64_t I = 0; I < Size; ++I) {
@@ -298,19 +300,22 @@ void emitMemsetExpansion(IRBuilder<> &Builder, Value *Dst, Value *Val,
298300
static void removeMemSet(Instruction &I,
299301
SmallVectorImpl<Instruction *> &ToRemove,
300302
DenseMap<Value *, Value *> &ReplacedValues) {
301-
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
302-
Intrinsic::ID ID = CI->getIntrinsicID();
303-
if (ID == Intrinsic::memset) {
304-
IRBuilder<> Builder(&I);
305-
Value *Dst = CI->getArgOperand(0);
306-
Value *Val = CI->getArgOperand(1);
307-
[[maybe_unused]] ConstantInt *Size =
308-
dyn_cast<ConstantInt>(CI->getArgOperand(2));
309-
assert(Size && "Expected Size to be a ConstantInt");
310-
emitMemsetExpansion(Builder, Dst, Val, Size, ReplacedValues);
311-
ToRemove.push_back(CI);
312-
}
313-
}
303+
304+
CallInst *CI = dyn_cast<CallInst>(&I);
305+
if (!CI)
306+
return;
307+
308+
Intrinsic::ID ID = CI->getIntrinsicID();
309+
if (ID != Intrinsic::memset)
310+
return;
311+
312+
IRBuilder<> Builder(&I);
313+
Value *Dst = CI->getArgOperand(0);
314+
Value *Val = CI->getArgOperand(1);
315+
ConstantInt *Size = dyn_cast<ConstantInt>(CI->getArgOperand(2));
316+
assert(Size && "Expected Size to be a ConstantInt");
317+
emitMemsetExpansion(Builder, Dst, Val, Size, ReplacedValues);
318+
ToRemove.push_back(CI);
314319
}
315320

316321
namespace {

0 commit comments

Comments
 (0)