Skip to content

Commit 11ecf5a

Browse files
mtargowsigcbot
authored andcommitted
Local variables no longer optimized out in off-loaded functions
1 parent ea7aff4 commit 11ecf5a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

IGC/Compiler/CISACodeGen/ResolveGAS.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,35 @@ bool GASResolving::resolveOnBasicBlock(BasicBlock* BB) const {
231231
CI->setOperand(0, Src);
232232
Changed = true;
233233
}
234+
235+
llvm::Module* ModuleMeta = BB->getModule();
236+
237+
if (CI->isUsedByMetadata()) {
238+
auto* L = LocalAsMetadata::getIfExists(CI);
239+
if (L) {
240+
auto* MDV = MetadataAsValue::getIfExists(ModuleMeta->getContext(), L);
241+
if (MDV) {
242+
SmallPtrSet<User*, 4> Users(MDV->users().begin(), MDV->users().end());
243+
for (auto U : Users) {
244+
if (isa<DbgDeclareInst>(cast<Value>(U)) || isa<DbgValueInst>(cast<Value>(U))) {
245+
CallInst* CallI = dyn_cast_or_null<CallInst>(cast<Value>(U));
246+
if (CallI) {
247+
MetadataAsValue* MAV = MetadataAsValue::get(CI->getContext(), ValueAsMetadata::get(Src));
248+
CallI->setArgOperand(0, MAV);
249+
Changed = true;
250+
}
251+
else {
252+
IGC_ASSERT_MESSAGE(false, "Unexpected instruction");
253+
}
254+
}
255+
else {
256+
IGC_ASSERT_MESSAGE(false, "Unexpected user");
257+
}
258+
}
259+
}
260+
}
261+
}
262+
234263
// Since %49 is used twice in a phi instruction like the one below:
235264
// %56 = phi %"class.someclass" addrspace(4)* [ %49, %53 ], [ %49, %742 ]
236265
// the use iterator was handling such phi instructions twice.

0 commit comments

Comments
 (0)