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

    <tr>
        <th>Summary</th>
        <td>
            Missed Optimization: Constant Store Not Folded in Nested Conditional Control Flow in the form of (C2 ? (C1 ? C1 : X) : (C1 ? C1 : Y))
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          GINN-Imp
      </td>
    </tr>
</table>

<pre>
    The following reduced IR is derived from https://github.com/HDFGroup/hdf5/blob/b08f2481a16b046f41c878c9d823b768f6e169f9/tools/lib/h5diff.c#L571

Godbolt: https://godbolt.org/z/zjeYa5ve5
alive2 proof: https://alive2.llvm.org/ce/z/krDdvM

In the following reduced IR, the final `store i32 %0` in `Block 5` could be optimized to `store i32 0` because `%0` is known to be zero on all paths leading to that block. Apologies if the ternary-like expression used in the title is not a fully precise abstraction; it is intended to describe the conditional control flow that masks the opportunity for optimization.

```llvm
@p = local_unnamed_addr global i32 0

define noundef i32 @h5diff(i32 %0, i1 %1) local_unnamed_addr #0 {
 %cond = icmp eq i32 %0, 0
  br i1 %1, label %3, label %4

3:
  store i32 1, ptr @p, align 4
  br i1 %cond, label %5, label %common.ret

common.ret:
  ret i32 0

4:          
  store i32 2, ptr @p, align 4
  br i1 %cond, label %5, label %common.ret

5:
  store i32 %0, ptr @p, align 4                                ; missed optimization: %0 --> 0
  br label %common.ret
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VU1v4zYQ_TX0ZWCDoj5sHXRwnCoN0E2BtofuaUGRI5sbiqOSlNPk1xeUnM_dbU8VbJDUzJt5fJyhZAjm6BAbVl6x8nolp3gi39zc3t2tb4dx1ZF-bP44IfRkLT0YdwSPelKo4fY3MAE0enNGDb2nAU4xjoHleyZaJtqjiaep2ygamGh_vm5vPE0j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