[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
Tue Jul 4 23:26:13 PDT 2023


dtcxzyw marked an inline comment as done.
dtcxzyw added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/binop-cast.ll:307
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:    [[RES:%.*]] = select i1 [[TMP1]], i32 [[Y]], i32 0
 ; CHECK-NEXT:    ret i32 [[RES]]
----------------
goldstein.w.n wrote:
> I'm not sure this isn't a regression.
> Generally I'd think `add; and` is as easier to analyze than `icmp; select` and likely to get better codegen. I think maybe this should only be done if we can actuall save inst count (so above require the `zext`).
`icmp; select` seems to get better codegen on x86-64 and aarch64.

x86-64: https://godbolt.org/z/jv9v9xTMT
riscv64: https://godbolt.org/z/zTbbnn9x4
aarch64: https://godbolt.org/z/eK6xWKnrb



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