Skip to content

Commit 546d48d

Browse files
grey-eminencesys_zuul
authored andcommitted
Cleaning redundant generic addrspacecast instructions
Change-Id: I53a25fd14d04bb54f8ae9678cf0aa9d36ecd0fd4
1 parent e5de625 commit 546d48d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/GenericAddressDynamicResolution.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,31 @@ bool GenericAddressDynamicResolution::runOnFunction(Function& F)
218218
}
219219
} while (changed);
220220

221+
// Cleaning redundant addrspacecast instructions
222+
// %1 = addrspacecast i32 * %buf to i32 addrspace(4) *
223+
// %2 = ptrtoint i32 addrspace(4) * %1 to i64
224+
// ->
225+
// %2 = ptrtoint i32 * %buf to i64
226+
for (inst_iterator i = inst_begin(F); i != inst_end(F); ++i)
227+
{
228+
if (AddrSpaceCastInst* addrSpaceCastInst = llvm::dyn_cast<AddrSpaceCastInst>(&*i))
229+
{
230+
if (addrSpaceCastInst->getSrcAddressSpace() == ADDRESS_SPACE_PRIVATE
231+
&& addrSpaceCastInst->getDestAddressSpace() == ADDRESS_SPACE_GENERIC
232+
&& addrSpaceCastInst->hasOneUse())
233+
{
234+
if (PtrToIntInst* ptrtoint = llvm::dyn_cast<PtrToIntInst>(*addrSpaceCastInst->user_begin()))
235+
{
236+
IRBuilder<> builder(addrSpaceCastInst);
237+
Value* newPtrToInt = builder.CreatePtrToInt(addrSpaceCastInst->getOperand(0), ptrtoint->getDestTy());
238+
ptrtoint->replaceAllUsesWith(newPtrToInt);
239+
ptrtoint->eraseFromParent();
240+
modified = true;
241+
}
242+
}
243+
}
244+
}
245+
221246
return modified;
222247
}
223248

0 commit comments

Comments
 (0)