Issue 146642
Summary [InstCombine] Missed optimization for icmp of select with constants and invertible binop
Labels llvm:instcombine, missed-optimization
Assignees
Reporter nikic
    We currently fail to fold variations of this pattern:

https://alive2.llvm.org/ce/z/tT3yNU
```llvm
define i1 @src(i64 %a, i1 %c) {
  %idx = shl nsw i64 %a, 3
  %sel = select i1 %c, i64 8, i64 0
  %cmp = icmp eq i64 %idx, %sel
  ret i1 %cmp
}

define i1 @tgt(i64 %a, i1 %c) {
  %sel = select i1 %c, i64 1, i64 0
  %cmp = icmp eq i64 %a, %sel
  ret i1 %cmp
}
```

The underlying pattern here is something like `f(x) == y` converted to `x == f^-1(y)` where f invertible and `f^-1(y)` folds because the shift arms are constant.

>From https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2524/files/9ca17b717ceea34b52263bf8b20cf12ad02cd4fd#r2179220735.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to