Skip to content

Commit e2d2aff

Browse files
authored
[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 iree-org/iree#22551
1 parent 3d0a367 commit e2d2aff

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,11 @@ void SplitPtrStructs::processConditionals() {
15651565
} else if (isa<SelectInst>(I)) {
15661566
if (MaybeRsrc) {
15671567
if (auto *RsrcInst = dyn_cast<Instruction>(Rsrc)) {
1568-
ConditionalTemps.push_back(RsrcInst);
1569-
RsrcInst->replaceAllUsesWith(*MaybeRsrc);
1568+
// Guard against conditionals that were already folded away.
1569+
if (RsrcInst != *MaybeRsrc) {
1570+
ConditionalTemps.push_back(RsrcInst);
1571+
RsrcInst->replaceAllUsesWith(*MaybeRsrc);
1572+
}
15701573
}
15711574
for (Value *V : Seen)
15721575
FoundRsrcs[V] = *MaybeRsrc;

llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-control-flow.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,15 @@ define void @dominance_not_in_program_order(ptr addrspace(7) inreg %arg) {
481481
%lsr.iv11 = phi ptr addrspace(7) [ %arg, %.loopexit ], [ %arg, %.preheader15 ]
482482
br label %.loopexit
483483
}
484+
485+
;; iree-org/iree#22551 - crash on something that reduces to the below non-canonical select.
486+
define ptr addrspace(7) @noncanonical_const_cond(ptr addrspace(7) %x) {
487+
; CHECK-LABEL: define { ptr addrspace(8), i32 } @noncanonical_const_cond
488+
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[RET:%.*]]) #[[ATTR0]] {
489+
; CHECK-NEXT: [[X_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[RET]], 0
490+
; CHECK-NEXT: [[X_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[RET]], 1
491+
; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[RET]]
492+
;
493+
%ret = select i1 false, ptr addrspace(7) %x, ptr addrspace(7) %x
494+
ret ptr addrspace(7) %ret
495+
}

0 commit comments

Comments
 (0)