Issue 233753
Summary Missed optimization about "abs(x) == 0" to "x == 0"
Labels new issue
Assignees
Reporter Misasasa
    ```
define i1 @src(i32 %x, i1 %cond) {
 %negx = sub i32 0, %x
  %somex = select i1 %cond, i32 %negx, i32 %x
  %ret = icmp eq i32 %somex, 0
  ret i1 %ret
}

define i1 @tgt(i32 %x, i1 %cond) {
  %ret = icmp eq i32 %x, 0
  ret i1 %ret
}
```
https://alive2.llvm.org/ce/z/7WQeXT

Interestingly, upon replacing `eq` with `ne`, opt immediately works:
```
define i1 @src(i32 %x, i1 %cond) {
  %negx = sub i32 0, %x
  %somex = select i1 %cond, i32 %negx, i32 %x
  %ret = icmp ne i32 %somex, 0
  ret i1 %ret
}

define i1 @tgt(i32 %x, i1 %cond) {
  %ret = icmp ne i32 %x, 0
  ret i1 %ret
}
```
https://alive2.llvm.org/ce/z/uEcR23

I find the corresponding pattern in https://github.com/llvm/llvm-project/blob/d89ee72b931cc1593352b07f6214b3b559519324/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L8017-L8031
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to