llvm / llvm/llvm-project

[AMDGPU] Assertion `BI.FirstInstr >= Start' failed.

Open
#176,538 1 comment 0 reactions 0 assignees View on GitHub
backend:AMDGPU crash-on-valid generated by fuzzer llvm:regalloc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/aosqsnz4K
Testcase:
```llvm
target datalayout = "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
target triple = "amdgcn-amd-amdhsa"

%struct.S1 = type { i8, %struct.S0 }
%struct.S0 = type { i64 }

define i16 @backsmith_pure_2(ptr addrspace(5) %BS_VAR_0, i1 %tobool.not, i64 %add919, <32 x i8> %shuffle57, <32 x i8> %vecinit827, <16 x i16> %0) #0 {
entry:
%BS_VAR_01 = alloca [8 x <32 x i8>], align 32, addrspace(5)
%call2 = call i8 @backsmith_snippet_44()
br i1 %tobool.not, label %if.end, label %if.then, !prof !0

if.then: ; preds = %entry
br i1 %tobool.not, label %for.cond.cleanup, label %for.body

for.cond.cleanup: ; preds = %for.body, %if.then
%call976 = call <4 x i64> @backsmith_pure_0(<16 x i16> zeroinitializer)
br label %if.end

for.body: ; preds = %for.body, %if.then
store <32 x i8> %shuffle57, ptr addrspace(5) %BS_VAR_0, align 32
%call394 = call <4 x i16> @backsmith_snippet_679()
%call393 = call <4 x i16> @backsmith_snippet_679()
%cmp104 = icmp ne <32 x i8> %vecinit827, zeroinitializer
%sext = sext <32 x i1> %cmp104 to <32 x i8>
%vecext347 = extractelement <32 x i8> %sext, i64 29
%cond893.v = select i1 %tobool.not, i8 0, i8 %vecext347
%vecinit895 = insertelement <32 x i8> %vecinit827, i8 %cond893.v, i64 29
store <32 x i8> %vecinit895, ptr addrspace(5) null, align 32
%exitcond.not = icmp eq i64 0, %add919
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body

if.end: ; preds = %for.cond.cleanup, %entry
%call1066 = call <4 x i64> @backsmith_pure_0(<16 x i16> %0)
ret i16 0
}

declare i8 @backsmith_snippet_44()

declare <4 x i16> @backsmith_snippet_679()

declare <4 x i64> @backsmith_pure_0(<16 x i16>)

define %struct.S1 @func_103(i8 %0, i1 %tobool2.not30) #0 {
entry:
%add = shufflevector <4 x i16> splat (i16 1), <4 x i16> zeroinitializer, <4 x i32> zeroinitializer
br label %for.cond1.preheader

for.cond.loopexit: ; preds = %for.end, %for.cond1.preheader
%tobool.not = icmp eq i8 %0, 0
br i1 %tobool.not, label %for.end25, label %for.cond1.preheader

for.cond1.preheader: ; preds = %for.cond.loopexit, %entry
br i1 %tobool2.not30, label %for.cond.loopexit, label %for.body3

for.body3: ; preds = %for.end, %for.cond1.preheader
br label %for.cond4

for.cond4: ; preds = %for.cond4, %for.body3
%tobool7.not = icmp eq i64 0, 0
br i1 %tobool7.not, label %for.end, label %for.cond4

for.end: ; preds = %for.cond4
%call121 = call i16 @backsmith_pure_2(ptr addrspace(5) null, i1 false, i64 0, <32 x i8> zeroinitializer, <32 x i8> zeroinitializer, <16 x i16> zeroinitializer)
store <4 x i16> %add, ptr addrspace(5) null, align 8
tail call void @backsmith_pure_7(<16 x i64> zeroinitializer, i32 -352674805, <2 x i32> splat (i32 -247168742))
tail call void @backsmith_pure_7(<16 x i64> zeroinitializer, i32 -352674805, <2 x i32> splat (i32 -247168742))
%tobool2.not = icmp eq ptr addrspace(5) null, null
br i1 %tobool2.not, label %for.cond.loopexit, label %for.body3

for.end25: ; preds = %for.cond.loopexit
ret %struct.S1 zeroinitializer
}

declare void @backsmith_pure_7(<16 x i64>, i32, <2 x i32>)

; uselistorder directives
uselistorder ptr @backsmith_snippet_679, { 1, 0 }
uselistorder ptr @backsmith_pure_0, { 1, 0 }
uselistorder ptr @backsmith_pure_7, { 1, 0 }

attributes #0 = { "target-cpu"="gfx1201" }

!0 = !{!"branch_weights", !"expected", i32 2000, i32 1}
```

Dump:
```
llc: /root/llvm-project/llvm/lib/CodeGen/SplitKit.cpp:233: void llvm::SplitAnalysis::calcLiveBlockInfo(): Assertion `BI.FirstInstr >= Start' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -O1
1. Running pass 'CallGraph Pass Manager' on module ''.
2. Running pass 'Greedy Register Allocator' on function '@func_103'
#0 0x0000000004252608 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4252608)
#1 0x000000000424f4e4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x000075cf6e242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x000075cf6e2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x000075cf6e242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x000075cf6e2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x000075cf6e22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#7 0x000075cf6e239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#8 0x000000000340f8a0 llvm::SplitAnalysis::analyzeUses() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x340f8a0)
#9 0x000000000340fab8 llvm::SplitAnalysis::analyzeUses() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x340fab8)
#10 0x000000000334da8f llvm::RAGreedy::tryAssignCSRFirstTime(llvm::LiveInterval const&, llvm::AllocationOrder&, llvm::MCRegister, unsigned char&, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x334da8f)
#11 0x00000000033552db llvm::RAGreedy::selectOrSplitImpl(llvm::LiveInterval const&, llvm::SmallVectorImpl&, llvm::SmallSet>&, llvm::SmallVector, 8u>&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x33552db)
#12 0x0000000003356017 llvm::RAGreedy::selectOrSplit(llvm::LiveInterval const&, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3356017)
#13 0x00000000035bdfd0 llvm::RegAllocBase::allocatePhysRegs() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x35bdfd0)
#14 0x0000000003351c1b llvm::RAGreedy::run(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3351c1b)
#15 0x000000000335286a (anonymous namespace)::RAGreedyLegacy::runOnMachineFunction(llvm::MachineFunction&) RegAllocGreedy.cpp:0:0
#16 0x000000000311d0e9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#17 0x0000000003773256 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3773256)
#18 0x0000000002b690c8 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
#19 0x0000000003773e6f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3773e6f)
#20 0x00000000008eb34d compileModule(char**, llvm::SmallVectorImpl&, llvm::LLVMContext&, std::__cxx11::basic_string, std::allocator>&) llc.cpp:0:0
#21 0x00000000007c6f8c main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7c6f8c)
#22 0x000075cf6e229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#23 0x000075cf6e229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#24 0x00000000008e03f5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x8e03f5)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

Contributor guide

Open the contributing guide

Research direction

Reproduce with llc at -O1 using the linked Godbolt testcase and the command shown in the report. Start at llvm/lib/CodeGen/SplitKit.cpp:233 and inspect the Greedy Register Allocator path for @func_103. Done means the AMDGPU testcase no longer triggers the BI.FirstInstr assertion and llc completes successfully.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.