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

    <tr>
        <th>Summary</th>
        <td>
            [SimplifyCFG] Missed optimization with nested branches
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:optimizations,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    Alive2: https://alive2.llvm.org/ce/z/5iOJEL
```
define void @src(i1 %cond1, i1 %cond2) {
entry:
  br i1 %cond1, label %bb1, label %bb2

bb1:
 br i1 %cond2, label %bb3, label %bb4

bb2:
  br i1 %cond2, label %bb4, label %bb3

bb3:
  call void @sideeffect1()
  ret void

bb4:
  call void @sideeffect2() 
  ret void
}

define void @tgt(i1 %cond1, i1 %cond2) {
entry:
 %cond = xor i1 %cond1, %cond2
  br i1 %cond, label %bb4, label %bb3

bb3:
  call void @sideeffect1()
  ret void

bb4:
 call void @sideeffect2() 
  ret void
}

declare void @sideeffect1()
declare void @sideeffect2()
```

I found this pattern in verilator-generated code. Handling this pattern will reduce branch cost.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzElM-OmzAQxp9muFiJzAABDhyym9I_atVDn8DYA7hycGSb7GafvoKkuwnb1UpVpUqRo7Fnfh5_Iz7hve4GogqyO0BUQT4-nR4AEbJdJMbQW1ddNqPGqlO1NfpICMmW9SEcPCRbwBqwFvP-2pjjfm1dB1hLAqyfAOtMf__y4SvwHfAtbPjlN4eKWj0QO1qtGKTcOwlY6JgBZtIOKga8Zy8hApYM8rtzLQ3Bnab754ixxrFFpRENmWmnaZYxXtqZ1-n4mXODwUVZsojTWwy-1c6Sk77i3nCSK44UxrwIpBVR25IMMWABWP7OchTmpFtO-j4Hzxz2BijfXRMX4wpd-OtxXXIYJDv2aF-N7hnxJzX_u5j_RktphKP3unk7Da_TFt_Vef3MWjsOioVee3YQIZAbmB7YkZw2Ili36mggJwIpJq2iNfskBmX00N2WPGhjmCM1SmKNE4PsmbQ-rK_vilSVqDIpRURVnMdltok3nEd9laWyyPMEi4TyjczLppRFLLjIRFq2cZtGukKOKd9gwQvOOV_LDeeoKG2zmKs8UZBy2gttns0l0t6PVJU5R4zmwfuLf00ZkGztIei9fhJB28FPZob3gLjX3pNaXR9ejM5VU-GqGTsPKTfaB_9yWdDBzP74Q-8PRren-_ojZDv2bcaxaxx70KFnA_lJ0bNS5KPRmerWLDsd-rFZS7sHrOeez3-rg7M_SQbAen6iB6zPrzxW-CsAAP__eXCk4g">