Issue 142744
Summary Missed optimization of constant folding when using 'trunc nuw i64 %v to i1'
Labels new issue
Assignees
Reporter GINN-Imp
    The following reduced IR is derived from https://github.com/rust-lang/regex/blob/1a069b9232c607b34c4937122361aa075ef573fa/regex-automata/src/util/pool.rs#L542.

Godbolt: https://godbolt.org/z/KebcfWbE8 (contains the source code before manual reduce)
alive2 proof: https://alive2.llvm.org/ce/z/XPqJVm

Missed optimization: `store i64 %v, ptr %p, align 8` --> `store i64 0, ptr %p, align 8`

While Alive2 proves this transformation to be correct, I’m not fully certain why this optimization is valid from a semantic standpoint — especially regarding how trunc nuw i64 %v to i1 constrains %v. Any clarification on why this optimization is valid would be appreciated.

```llvm
define i64 @src(ptr %p, i64 %v) {
  %trunc = trunc nuw i64 %v to i1
  br i1 %trunc, label %common.ret, label %3

common.ret:                                       ; preds = %1, %3
  ret i64 0

3:                                                ; preds = %1
  store i64 %v, ptr %p, align 8
  br label %common.ret
}
```

expected:
```llvm
define i64 @tgt(ptr %p, i64 %v) {
  %trunc = trunc nuw i64 %v to i1
  br i1 %trunc, label %common.ret, label %3

common.ret:                                       ; preds = %1, %3
  ret i64 0

3:                                                ; preds = %1
  store i64 0, ptr %p, align 8
  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