Issue 150606
Summary Missed Optimization: Constant Store Not Folded in Nested Conditional Control Flow in the form of (C2 ? (C1 ? C1 : X) : (C1 ? C1 : Y))
Labels new issue
Assignees
Reporter GINN-Imp
    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
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to