[llvm] [CVP]: Fold `icmp eq X, C` to `trunc X to i1` if C=2k+1 and X in [2k, 2k+1] (PR #83829)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 10:20:34 PST 2024


YanWQ-monad wrote:

For most of the regression cases, they probably follow this form:
https://github.com/dtcxzyw/llvm-opt-benchmark/pull/286/files#diff-39f660d670ba4b7db20a130f81413c2584fbdbc537f1557976e334ecd34750c7L6491-R6493
``` diff
- %cmp18 = icmp eq i32 %encoding, 5
- br i1 %cmp18, label %cond.true19, label %cond.false22
+ %17 = and i32 %encoding, 1
+ %.not = icmp eq i32 %17, 0
+ br i1 %.not, label %cond.false22, label %cond.true19
```

It seems that it's not necessarily regression.

In terms of this IR,

``` llvm
define i1 @src(i32 %x) {
  %y = icmp ne i32 %x, 0
  ret i1 %y
}

define i1 @tgt(i32 %x) {
  %1 = and i32 %x, 1
  %y = icmp ne i32 %1, 0
  ret i1 %y
}
```

On x86 and RISC-V, it generates same number of instructions. On AArch64, the number of instructions it generated has reduced by one.
Link: x86 and AArch64: https://godbolt.org/z/az9sP1nf7, RISC-V: https://godbolt.org/z/nzdM7515M.

---

For the other regressions, I'm still trying to resolve them.

https://github.com/llvm/llvm-project/pull/83829


More information about the llvm-commits mailing list