[AMDGPU][LowerBufferFatPointers] Fix crash with select false (#166471)

If the input to LowerBufferFatPointers is such that the resource- and
offset-specific `select` instructions generated for a `select` on `ptr
addrspae(7)` fold away, the pass would crash when trying to replace an
instruction with itself. This commit resolves the issue.

Fixes https://github.com/iree-org/iree/issues/22551
This commit is contained in:
Krzysztof Drewniak 2025-11-05 11:21:52 -08:00 committed by GitHub
parent 3d0a3674d9
commit e2d2affc70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -1565,8 +1565,11 @@ void SplitPtrStructs::processConditionals() {
} else if (isa<SelectInst>(I)) {
if (MaybeRsrc) {
if (auto *RsrcInst = dyn_cast<Instruction>(Rsrc)) {
ConditionalTemps.push_back(RsrcInst);
RsrcInst->replaceAllUsesWith(*MaybeRsrc);
// Guard against conditionals that were already folded away.
if (RsrcInst != *MaybeRsrc) {
ConditionalTemps.push_back(RsrcInst);
RsrcInst->replaceAllUsesWith(*MaybeRsrc);
}
}
for (Value *V : Seen)
FoundRsrcs[V] = *MaybeRsrc;

View File

@ -481,3 +481,15 @@ define void @dominance_not_in_program_order(ptr addrspace(7) inreg %arg) {
%lsr.iv11 = phi ptr addrspace(7) [ %arg, %.loopexit ], [ %arg, %.preheader15 ]
br label %.loopexit
}
;; iree-org/iree#22551 - crash on something that reduces to the below non-canonical select.
define ptr addrspace(7) @noncanonical_const_cond(ptr addrspace(7) %x) {
; CHECK-LABEL: define { ptr addrspace(8), i32 } @noncanonical_const_cond
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[RET:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[X_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[RET]], 0
; CHECK-NEXT: [[X_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[RET]], 1
; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[RET]]
;
%ret = select i1 false, ptr addrspace(7) %x, ptr addrspace(7) %x
ret ptr addrspace(7) %ret
}