Skip to content

Commit 7897517

Browse files
authored
[SYCL][ESIMD] Relax LowerESIMDSlmReservation assert (#11035)
We may end up with the basic block containing the slm_init call having multiple predecessors, causing an assert. This pattern will not cause any problems as the slm_init size is the same, so just skip these basic blocks. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 499b4bf commit 7897517

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMDSlmReservation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ class ScopedCallGraph {
330330
// Do preorder traversal so that successors are visited after the parent.
331331
while (Wl.size() > 0) {
332332
BasicBlock *BB = Wl.pop_back_val();
333+
334+
// If we have already visited this BB but it
335+
// made it into the worklist, that means this BB
336+
// has multiple predecessors. We already processed the first one
337+
// so just skip it.
338+
if (Visited.contains(BB))
339+
continue;
340+
333341
Visited.insert(BB);
334342

335343
for (Instruction &I : *BB) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; This test confirms we don't assert for a single slm_init call
2+
; in a basic block with two predecessors.
3+
;
4+
; RUN: opt < %s -passes=LowerESIMD -S | FileCheck %s
5+
6+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
7+
target triple = "spir64-unknown-unknown"
8+
9+
@__spirv_BuiltInGlobalInvocationId = external dso_local local_unnamed_addr addrspace(1) constant <3 x i64>, align 32
10+
11+
; Function Attrs: convergent nounwind
12+
declare dso_local spir_func void @_Z16__esimd_slm_initj(i32 noundef) local_unnamed_addr
13+
14+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
15+
declare void @llvm.assume(i1 noundef)
16+
17+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
18+
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
19+
20+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
21+
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
22+
23+
; Function Attrs: convergent norecurse nounwind
24+
define weak_odr dso_local spir_kernel void @foo() local_unnamed_addr #0 !sycl_explicit_simd !0 {
25+
entry:
26+
%x.i = alloca i32, align 4
27+
%0 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId, align 32
28+
%cmp.i.i = icmp ult i64 %0, 2147483648
29+
tail call void @llvm.assume(i1 %cmp.i.i)
30+
%tobool.not.i = icmp eq i64 %0, 0
31+
br i1 %tobool.not.i, label %foo.exit, label %if.then.i
32+
33+
if.then.i: ; preds = %entry
34+
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %x.i)
35+
%1 = addrspacecast ptr %x.i to ptr addrspace(4)
36+
store volatile i32 0, ptr addrspace(4) %1, align 4
37+
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %x.i)
38+
br label %foo.exit
39+
40+
; CHECK: foo.exit:
41+
; CHECK-NEXT: ret void
42+
foo.exit: ; preds = %entry, %if.then.i
43+
tail call spir_func void @_Z16__esimd_slm_initj(i32 noundef 100) #4
44+
ret void
45+
}
46+
47+
attributes #0 = { convergent norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="test.cpp" "sycl-optlevel"="2" "uniform-work-group-size"="true" }
48+
49+
!0 = !{}

0 commit comments

Comments
 (0)