<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64215>64215</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [LICM] LLVM ERROR: Instruction does not dominate all uses on callbr instruction
        </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>
    The following IR which is extracted from the `llvm/test/Transforms/InstCombine/freeze.ll` unit test file causes an LLVM ERROR when passed into `opt` with `-passes="default<O3>"`
```llvm
declare void @use_i32(i32)

define i32 @freeze_callbr_use_after_phi(i1 %c) {
entry:
  %x = callbr i32 asm sideeffect "", "=r"()
 to label %callbr.cont []

callbr.cont: ; preds = %callbr.cont, %entry
  %phi = phi i32 [ %x, %entry ], [ 0, %callbr.cont ]
  call void @use_i32(i32 %x)
  %fr = freeze i32 %x
 call void @use_i32(i32 %fr)
  call void @use_i32(i32 %phi)
  br label %callbr.cont
}
```
Here is the error on godbolt: https://godbolt.org/z/GPa4nY399. And here is the corresponding stack dump:
```shell
Instruction does not dominate all uses!
  %x = callbr i32 asm sideeffect "", "=r"() #1
          to label %callbr.cont []
  %fr = freeze i32 %x
Instruction does not dominate all uses!
 %x = callbr i32 asm sideeffect "", "=r"() #1
          to label %callbr.cont []
  tail call void @use_i32(i32 %x)
Instruction does not dominate all uses!
  %x = callbr i32 asm sideeffect "", "=r"() #1
 to label %callbr.cont []
  tail call void @use_i32(i32 %x)
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=default<O3> <source>
 #0 0x000000000348c6a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x348c6a8)
 #1 0x0000000003489f9c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007ff836c5d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007ff83672000b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007ff8366ff859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x0000000000780e2d (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x780e2d)
 #6 0x00000000033e17f8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x33e17f8)
 #7 0x0000000002e1e433 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1e433)
 #8 0x000000000087a5de 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+0x87a5de)
 #9 0x0000000002de398c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2de398c)
#10 0x000000000088470a 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, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x88470a)
#11 0x000000000078c0c1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x78c0c1)
#12 0x00007ff836701083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#13 0x000000000087994e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x87994e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
>From a quick look at the pipeline, it looks like the culprit is the LICM pass (https://godbolt.org/z/9P48WTEGc).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWEtv4zgS_jX0pRCDIiVZOviQl3uC7aCDTtCLPRmUVLK5oUktSXWS-fULUvJDmfRMeiaLAdZQIolV_OrBKhZLwjm50YhLkl2Q7Gomer81dolW1kr2_awyzcvyYYvQGqXMk9QbuPkKT1tZb0E6wGdvRe2xgdaaHfgtAsmpUt93hK08Ok_Y6sEK7Vpjd46w1Y12_tLsKqmRsFVrEX_FuVIkp9Br6SHMgVYqhFr0Dh0IDZ8_f7uF669fvwTBqKETzmEDUnsTpJnOh-lP0m_D61kkO8KvCGMNtqJXnvDLL5zwa8IYySmhV4Seh4d4RW3jUIO1Ehbhu5ENkJT2DteSM8KK-L8cJ468rdQIkrPAORiyroVSlV2HeaL1aNfdVobZCRCW1YSVQBYXw3zU3r4QPqJBYHgGwq9gwIjAwu3AyQaxbbH2ELQP12V84lc2vhUHxcAbUKJCFaVFmHlttIdhbU-1P6ESfg6EX0BnsXFRg-nsQV426HtUttvKyBzu0QnZRbThlB2C1PCeXQAdCVO9rvaIYfhtv4-o5Yns1kbRg9PhwDMw_D5Sa0-gfp81rt2Bt7Jv-nZ06uLqVVANr7-gxZAmIS_QWmPBaNiYpjIq-n3rfedCELAVYauRMDd2Q9jqV8JWn-5Eqv_Fy3IO57qB7QlcbaxF1xndhJx0XtSP0PS77hBSB1XcFpUaxkL22b720mhoDDrQxkNjdlILjxC8EXKOsORDohII4wek_e89MfqHi_yzdvxdZngh1btD--9bnP-BMcc9O8T5hTWPqGFnml6FUtLrJuhUm10nlYgWi8pYj83BvLvP1-f31-D6aic9CKj6DVjsjPVB3VeJI_22r-a1CVVnLD7hdtZZ82-sQxGSzvXBeSsQOpSOWvUNDolkhdtCJerHUMpwPoi__21C0Tmh5Z01Gyt2IOym36H2Lm6fbBWKEFsNB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