File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments