[PATCH] D153148: [InstCombine] Fold `(-1 + A) & B` into `A ? 0 : B` where A is effectively a bool

Yingwei Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 25 04:40:21 PDT 2023


dtcxzyw added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/binop-cast.ll:302
 
 ; Negative test of and_add_bool_to_select
 define i32 @and_add_bool_no_fold(i32 %y) {
----------------
nikic wrote:
> This isn't a negative test?
It was added as a negative test since @goldstein.w.n thought it should be a regression.
However, I tested the inst seq on some backends and found that `icmp; select` seems to get better codegen.

x86-64: https://godbolt.org/z/jv9v9xTMT
riscv64: https://godbolt.org/z/zTbbnn9x4
riscv64 (sifive-u74 with SFB opt): https://godbolt.org/z/aKjEs5n1P (`icmp; select` only costs 2 cycles with SFB)
aarch64: https://godbolt.org/z/eK6xWKnrb

I think the pattern `select i1 %x, i32 %y, i32 0` is more likely to get better codegen.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153148/new/

https://reviews.llvm.org/D153148



More information about the llvm-commits mailing list