Skip to content

Commit fb35741

Browse files
committed
Revert "[DirectX] legalize memset (llvm#136244)"
This reverts commit 02e316c.
1 parent 3275291 commit fb35741

File tree

2 files changed

+4
-208
lines changed

2 files changed

+4
-208
lines changed

llvm/lib/Target/DirectX/DXILLegalizePass.cpp

+4-83
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "llvm/IR/InstIterator.h"
1414
#include "llvm/IR/Instruction.h"
1515
#include "llvm/IR/Instructions.h"
16-
#include "llvm/IR/Module.h"
1716
#include "llvm/Pass.h"
1817
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
1918
#include <functional>
@@ -175,22 +174,16 @@ static void upcastI8AllocasAndUses(Instruction &I,
175174

176175
Type *SmallestType = nullptr;
177176

177+
// Gather all cast targets
178178
for (User *U : AI->users()) {
179179
auto *Load = dyn_cast<LoadInst>(U);
180180
if (!Load)
181181
continue;
182182
for (User *LU : Load->users()) {
183-
Type *Ty = nullptr;
184-
if (auto *Cast = dyn_cast<CastInst>(LU))
185-
Ty = Cast->getType();
186-
if (CallInst *CI = dyn_cast<CallInst>(LU)) {
187-
if (CI->getIntrinsicID() == Intrinsic::memset)
188-
Ty = Type::getInt32Ty(CI->getContext());
189-
}
190-
191-
if (!Ty)
183+
auto *Cast = dyn_cast<CastInst>(LU);
184+
if (!Cast)
192185
continue;
193-
186+
Type *Ty = Cast->getType();
194187
if (!SmallestType ||
195188
Ty->getPrimitiveSizeInBits() < SmallestType->getPrimitiveSizeInBits())
196189
SmallestType = Ty;
@@ -246,77 +239,6 @@ downcastI64toI32InsertExtractElements(Instruction &I,
246239
}
247240
}
248241

249-
static void emitMemsetExpansion(IRBuilder<> &Builder, Value *Dst, Value *Val,
250-
ConstantInt *SizeCI,
251-
DenseMap<Value *, Value *> &ReplacedValues) {
252-
LLVMContext &Ctx = Builder.getContext();
253-
[[maybe_unused]] const DataLayout &DL =
254-
Builder.GetInsertBlock()->getModule()->getDataLayout();
255-
[[maybe_unused]] uint64_t OrigSize = SizeCI->getZExtValue();
256-
257-
AllocaInst *Alloca = dyn_cast<AllocaInst>(Dst);
258-
259-
assert(Alloca && "Expected memset on an Alloca");
260-
assert(OrigSize == Alloca->getAllocationSize(DL)->getFixedValue() &&
261-
"Expected for memset size to match DataLayout size");
262-
263-
Type *AllocatedTy = Alloca->getAllocatedType();
264-
ArrayType *ArrTy = dyn_cast<ArrayType>(AllocatedTy);
265-
assert(ArrTy && "Expected Alloca for an Array Type");
266-
267-
Type *ElemTy = ArrTy->getElementType();
268-
uint64_t Size = ArrTy->getArrayNumElements();
269-
270-
[[maybe_unused]] uint64_t ElemSize = DL.getTypeStoreSize(ElemTy);
271-
272-
assert(ElemSize > 0 && "Size must be set");
273-
assert(OrigSize == ElemSize * Size && "Size in bytes must match");
274-
275-
Value *TypedVal = Val;
276-
277-
if (Val->getType() != ElemTy) {
278-
if (ReplacedValues[Val]) {
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-
TypedVal = ReplacedValues[Val];
283-
284-
} else {
285-
// This case Val is a ConstantInt so the cast folds away.
286-
// However if we don't do the cast the store below ends up being
287-
// an i8.
288-
TypedVal = Builder.CreateIntCast(Val, ElemTy, false);
289-
}
290-
}
291-
292-
for (uint64_t I = 0; I < Size; ++I) {
293-
Value *Offset = ConstantInt::get(Type::getInt32Ty(Ctx), I);
294-
Value *Ptr = Builder.CreateGEP(ElemTy, Dst, Offset, "gep");
295-
Builder.CreateStore(TypedVal, Ptr);
296-
}
297-
}
298-
299-
static void removeMemSet(Instruction &I,
300-
SmallVectorImpl<Instruction *> &ToRemove,
301-
DenseMap<Value *, Value *> &ReplacedValues) {
302-
303-
CallInst *CI = dyn_cast<CallInst>(&I);
304-
if (!CI)
305-
return;
306-
307-
Intrinsic::ID ID = CI->getIntrinsicID();
308-
if (ID != Intrinsic::memset)
309-
return;
310-
311-
IRBuilder<> Builder(&I);
312-
Value *Dst = CI->getArgOperand(0);
313-
Value *Val = CI->getArgOperand(1);
314-
ConstantInt *Size = dyn_cast<ConstantInt>(CI->getArgOperand(2));
315-
assert(Size && "Expected Size to be a ConstantInt");
316-
emitMemsetExpansion(Builder, Dst, Val, Size, ReplacedValues);
317-
ToRemove.push_back(CI);
318-
}
319-
320242
namespace {
321243
class DXILLegalizationPipeline {
322244

@@ -348,7 +270,6 @@ class DXILLegalizationPipeline {
348270
LegalizationPipeline.push_back(fixI8UseChain);
349271
LegalizationPipeline.push_back(downcastI64toI32InsertExtractElements);
350272
LegalizationPipeline.push_back(legalizeFreeze);
351-
LegalizationPipeline.push_back(removeMemSet);
352273
}
353274
};
354275

llvm/test/CodeGen/DirectX/legalize-memset.ll

-125
This file was deleted.

0 commit comments

Comments
 (0)