Skip to content

Commit 96ce9f9

Browse files
authored
[AMDGPU] Prevent re-visits in LowerBufferFatPointers (#159168)
Fixes iree-org/iree#22001 The visitor in SplitPtrStructs would re-visit instructions if an instruction earlier in program order caused a recursive visit() call via getPtrParts(). This would cause instructions to be processed multiple times. As a consequence of this, PHI nodes could be added to the Conditionals array multiple times, which would to a conditinoal that was already simplified being processed multiple times. After the code moved to InstSimplifyFolder, this re-processing, combined with more agressive simplifications, would lead to an attempt to replace an instruction with itself, causing an assertion failure and crash. This commit resolves the issue and adds the reduced form of the crashing input as a test.
1 parent 7bdd88c commit 96ce9f9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,12 @@ void SplitPtrStructs::processFunction(Function &F) {
23282328
LLVM_DEBUG(dbgs() << "Splitting pointer structs in function: " << F.getName()
23292329
<< "\n");
23302330
for (Instruction *I : Originals) {
2331+
// In some cases, instruction order doesn't reflect program order,
2332+
// so the visit() call will have already visited coertain instructions
2333+
// by the time this loop gets to them. Avoid re-visiting these so as to,
2334+
// for example, avoid processing the same conditional twice.
2335+
if (SplitUsers.contains(I))
2336+
continue;
23312337
auto [Rsrc, Off] = visit(I);
23322338
assert(((Rsrc && Off) || (!Rsrc && !Off)) &&
23332339
"Can't have a resource but no offset");

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,29 @@ loop:
455455
exit:
456456
ret float %sum
457457
}
458+
459+
define void @dominance_not_in_program_order(ptr addrspace(7) inreg %arg) {
460+
; CHECK-LABEL: define void @dominance_not_in_program_order
461+
; CHECK-SAME: ({ ptr addrspace(8), i32 } inreg [[ARG:%.*]]) #[[ATTR0]] {
462+
; CHECK-NEXT: .preheader15:
463+
; CHECK-NEXT: [[ARG_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[ARG]], 0
464+
; CHECK-NEXT: [[ARG_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[ARG]], 1
465+
; CHECK-NEXT: br label [[DOTLR_PH18:%.*]]
466+
; CHECK: .loopexit:
467+
; CHECK-NEXT: [[SCEVGEP12:%.*]] = add i32 [[LSR_IV11_OFF:%.*]], 16
468+
; CHECK-NEXT: br label [[DOTLR_PH18]]
469+
; CHECK: .lr.ph18:
470+
; CHECK-NEXT: [[LSR_IV11_OFF]] = phi i32 [ [[ARG_OFF]], [[DOTLOOPEXIT:%.*]] ], [ [[ARG_OFF]], [[DOTPREHEADER15:%.*]] ]
471+
; CHECK-NEXT: br label [[DOTLOOPEXIT]]
472+
;
473+
.preheader15:
474+
br label %.lr.ph18
475+
476+
.loopexit: ; preds = %.lr.ph18
477+
%scevgep12 = getelementptr i8, ptr addrspace(7) %lsr.iv11, i32 16
478+
br label %.lr.ph18
479+
480+
.lr.ph18: ; preds = %.loopexit, %.preheader15
481+
%lsr.iv11 = phi ptr addrspace(7) [ %arg, %.loopexit ], [ %arg, %.preheader15 ]
482+
br label %.loopexit
483+
}

0 commit comments

Comments
 (0)