<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62402>62402</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine] LLVM ERROR: instruction precedes `landingpad` intrinsic after optimization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ericliuu
</td>
</tr>
</table>
<pre>
Reproducer: https://godbolt.org/z/sea53Wsda
Crashing input before optimization:
```llvm
define <4 x float> @bad3(float %a) {
%t = insertelement <4 x float> poison, float %a, i32 0
%out.i = callbr i32 asm "# $0", "=r,!i"()
to label %direct.i [label %entry.indirect_crit_edge.i]
entry.indirect_crit_edge.i: ; preds = %0
%1 = call i32 @llvm.callbr.landingpad.i32(i32 %out.i)
%t6 = insertelement <4 x float> %t, float %a, i32 %1
ret <4 x float> %t6
direct.i: ; preds = %0
unreachable
}
```
Crashing input after the InstCombine pass:
```llvm
define <4 x float> @bad3(float %a) {
%out.i = callbr i32 asm "# $0", "=r,!i"() #1
to label %direct.i [label %entry.indirect_crit_edge.i]
entry.indirect_crit_edge.i: ; preds = %0
%t = insertelement <4 x float> poison, float %a, i64 0
%1 = call i32 @llvm.callbr.landingpad.i32(i32 %out.i)
%t6 = insertelement <4 x float> %t, float %a, i32 %1
ret <4 x float> %t6
direct.i: ; preds = %0
unreachable
}
```
Here is the stack dump:
```
No other instructions may proceed intrinsic
%1 = call i32 @llvm.callbr.landingpad.i32(i32 %out.i)
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=instcombine <source>
#0 0x000055ac72b0cf8f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x357cf8f)
#1 0x000055ac72b0a6b4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007fd2fb1bc420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007fd2fac8900b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007fd2fac68859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x000055ac6fe0913e llvm::SuffixTree::insertLeaf(llvm::SuffixTreeNode&, unsigned int, unsigned int) (.cold) SuffixTree.cpp:0:0
#6 0x000055ac72a60f5e (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x34d0f5e)
#7 0x000055ac72442753 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2eb2753)
#8 0x000055ac6fef28f6 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9628f6)
#9 0x000055ac7240662d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e7662d)
#10 0x000055ac6fefe435 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x96e435)
#11 0x000055ac6fe13d86 main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x883d86)
#12 0x00007fd2fac6a083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#13 0x000055ac6fef1a0e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x961a0e)
Compiler returned: 139
```
As the title says, it looks like the InstCombine pass moves the `insertelement` instruction in front of the `landingpad` intrinsic in the same basic block which triggers a verifier error.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWE1v4zgS_TX0pRCBJiVZPvjgODGmsZ2ZIGnMHg1KKsncUKRAUt3J_PoFKSeR8jHITGeBxWINJ7bI4ivW42ORZeGcbDXihmTnJLtYiMEfjd2glZWSw7AoTf2wucHemnqo0BK-haP3vSN8S9iesH1r6tIonxjbErb_g7C9Q5Hxf7paEHpB6HZnhTtK3YLU_eChxMZYBNN72ck_hJdGB6xoSnI6vpX63o1NNTZSIxC-S-EeGmWEJ_wSSEpLUXPCitgEhGWCsDWQ1fk4DkKTB8IvQGqH1qPCDrV_hdQb6YwmbAdTpB1IzoBOsMzgExnxKqFUaaOBcB0QxgjjQFhK49ddbOEXlrAdYUsZGwvC1o9gjy9vQIkSVUCvpcUqOsjOnxpRe_uQSD12Hior_QHrFhNJsosTY_H_nxjyLRB-Dr3F2sXZE5ZNw1o-hRQDImnkPhljTJTQtdRtL-pE8hBGtDmRMQkpcJ1_gOxg9zbVYSqPaBbfHplPY35kLET40df7TAzaoqiOolR4crK6eKHJqfMXmhaNRwv-iPBFO78zXRk02wvn_mPS_nk5AmF8-V-pyZ_atnkK_9f3S1b_orx_QYsgXVS086K6g3ro-tdaHh9_NWD8EW3gxtuhCindQSceoLemQqxBam-ldrL65IX5-vX3K7i8ufntJrB0bs0dauhMPSiExgy6DuxXpuuligcNiNJYjzVhp7W4_nq5vb0EN5Sd9CCgHFqw2Bvrw054cdBJfxzKpDIdYfu4i8ePs96af2HlCdtL5wZ0hO1B6BB1pYYaI4tVSBhQiurOW1FhMrq_fc0tTQhdX1vTWtGBsO0QdObilmF70wcvY0Boz_C-V8aiDW1K6PZMuCDOQP-Zt4O-I2xfSj0OhDMTIETfh-fB94NPHJzdwlnIU-gIvwjrV52SF-E7ZwZbIeGXp1Uj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