Skip to content

Commit 8d40bbf

Browse files
aratajewsys_zuul
authored andcommitted
Fix select handling in ResolveGAS
Change-Id: I2e064597ad6ea14b2276d4b3d6202aea8110a3e0
1 parent d3c4162 commit 8d40bbf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

IGC/Compiler/CISACodeGen/ResolveGAS.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,29 @@ bool GASPropagator::visitSelect(SelectInst& I) {
476476
if (!ASCI || ASCI->getSrcTy() != NonGASTy)
477477
return false;
478478

479+
// Change select operands to non-GAS
479480
TheUse->set(TheVal);
480481
TheOtherUse->set(ASCI->getOperand(0));
481482

483+
// Handle select return type
484+
BuilderType::InsertPointGuard Guard(*IRB);
485+
IRB->SetInsertPoint(&(*std::next(BasicBlock::iterator(&I))));
486+
487+
PointerType* DstPtrTy = cast<PointerType>(I.getType());
488+
PointerType* NonGASPtrTy = dyn_cast<PointerType>(NonGASTy);
489+
490+
// Push 'addrspacecast' forward by changing the select return type to non-GAS pointer
491+
// followed by a new 'addrspacecast' to GAS
492+
PointerType* TransPtrTy = PointerType::get(DstPtrTy->getElementType(), NonGASPtrTy->getAddressSpace());
493+
I.mutateType(TransPtrTy);
494+
Value* NewPtr = IRB->CreateAddrSpaceCast(&I, DstPtrTy);
495+
496+
for (auto UI = I.use_begin(), UE = I.use_end(); UI != UE;) {
497+
Use& U = *UI++;
498+
if (U.getUser() == NewPtr)
499+
continue;
500+
U.set(NewPtr);
501+
}
482502
return true;
483503
}
484504

0 commit comments

Comments
 (0)