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

    <tr>
        <th>Summary</th>
        <td>
            [CodeGenPrepare] Crash with `Instruction does not dominate all uses!`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:codegen,
            crash-on-valid,
            generated by fuzzer
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            dtcxzyw
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dtcxzyw
      </td>
    </tr>
</table>

<pre>
    Reproducer: https://godbolt.org/z/5Tn91av37
```
; bin/opt -codegenprepare test.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @main(i1 %cond) {
entry:
  %conv52.i.i.i = select i1 %cond, i64 2, i64 0
  br label %for.body36.i.i

for.body36.i.i:                                   ; preds = %for.body36.i.i, %entry
  %indvars.iv1225.i.i = phi i64 [ 0, %entry ], [ %indvars.iv.next1226.i.i, %for.body36.i.i ]
  %conv49.i.i.i = zext i1 %cond to i64
  %narrow.i.i.i.i = add nuw i64 %indvars.iv1225.i.i, %conv49.i.i.i
 %rem.i.i.i.i = urem i64 %narrow.i.i.i.i, %conv52.i.i.i
 %indvars.iv.next1226.i.i = add nuw i64 %indvars.iv1225.i.i, 1
  %exitcond = icmp eq i64 %indvars.iv.next1226.i.i, 3
  br i1 %exitcond, label %exit, label %for.body36.i.i

exit:
  ret void
}
```

```
Instruction does not dominate all uses!
  %conv49.i.i.i = zext i1 %cond to i64
  %0 = phi i64 [ %conv49.i.i.i, %entry ], [ %3, %for.body36.i.i ]
in function main
LLVM ERROR: Broken function 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 -codegenprepare <source>
1.      Running pass 'Function Pass Manager' on module '<source>'.
2.      Running pass 'Module Verifier' on function '@main'
 #0 0x000000000566b6e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x566b6e8)
 #1 0x0000000005668594 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x0000765e64c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000765e64c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x0000765e64c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x0000765e64c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000000000082696d llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0
 #7 0x00000000055a2b41 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x55a2b41)
 #8 0x00000000054c6c32 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) Verifier.cpp:0:0
 #9 0x00000000054079ff llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54079ff)
#10 0x0000000005407db1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5407db1)
#11 0x0000000005408621 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5408621)
#12 0x00000000009624e1 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9624e1)
#13 0x0000765e64c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#14 0x0000765e64c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#15 0x0000000000958f35 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x958f35)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8WN1y4yoSfhpyQ9mF0P-FL5Qfz87WzE4qPjW3KSTaMicSaAElTp5-CyTFkidnN5lNHY_HgRb99ddN07TNjBG1BNig-BJRym11fHl-QpSi-PqC9fag9GYUXpSKP2_uoNOK9xVoFBb4YG1nUFggukV0Wyteqsaula4R3b4guo3_kHnAHsMUkQIlZHyTAoWXuBQS0a3qLF5VikMNstPQMQ3YgrHrpsGrHSKFZboGizmzrGHPqrcYhdcYUQqrFoUFrDqaEhQWIfUfbhosp26URP5jJV4HAc1QWAQ0W-0zMo6kFyWTehKtdm4ZpSceVouugYnDMUvuk2jVywepnuSqEbI_rmrZDyqIFBz2QgJ-VIJjFJGWOaczEWBE40pJjmiOUXqJSAHS6mcXSlLg8eljTNfC_fPmDDRQWTzXvcIiiTCdBsTrlho3rITGLdsrvXbbFiYOZqB0JgsL_L9fbr86DdyMjp8D0ysnHFwY-QvJH5k2a_EYUBq_etEdhOeK4ktM5noYxdd-Hl8u1dcSjjagdG5pad6rzsIW5bOwvcBxHjRslbM_LZdMa_U0LB8VGOdY9k8Dy7f8GDnMLTk4RGMN7QKq19BOOEtLM4xpk0eMv3D8_dSCyTc4CutddqqiajsM__5V9ZfwhlMWDUGbUNyj17xywoXgrUTzi8aE1mD9IXBP0uvzarCcfpXG6r6yQknMFRgslcVctUIyC5g1De4NGESD39xz8ksinu_mX6dl-N8SUEi87-VA3J90Unz79vM7vrm7-3HnDtqlVg8wW7RX_RDYSrWdaJgXslJpC3zw7_bbTbG7waYvW2Exw2VfYw2d0tY5dVZ-hT305bpSLaLbpnmc_qw6rf6EyiK6Fcb0LnRbzCTHQlZNzwHbA-BKM3PAJaserGYVrBEpdpZVD5j3bTfsIlkjkt9qVWvWYqbrvgVpnXk81HFEt4MfoFdw7BqlQTtZw2S9YsaAdv6ZldW9fEB0O7sAlINgXefmve16uzZ4tfvlYkDhlVG9rgCFN4gUgSN010spZI07Z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