[InstCombine] Fold binop of `select` and cast of `select` condition
authorAntonio Frighetto <me@antoniofrighetto.com>
Wed, 5 Jul 2023 14:34:09 +0000 (16:34 +0200)
committerAntonio Frighetto <me@antoniofrighetto.com>
Thu, 20 Jul 2023 19:42:58 +0000 (19:42 +0000)
commitf12a5561b2cbfae384c9a31293938ee2acea79fd
tree93696b7495f945e6ffb3ad635cd3f3ec8be1e411
parentc9fd7ac3c5de7265bcd96be586340b1161e67491
[InstCombine] Fold binop of `select` and cast of `select` condition

Simplify binary operations, whose operands involve a `select`
instruction and a cast of the `select` condition. Specifically,
the binop is canonicalized into a `select` with folded arguments
as follows:

(Binop (zext C), (select C, T, F))
  -> (select C, (binop 1, T), (binop 0, F))

(Binop (sext C), (select C, T, F))
  -> (select C, (binop -1, T), (binop 0, F))

Proofs: https://alive2.llvm.org/ce/z/c_JwwM

Differential Revision: https://reviews.llvm.org/D153963
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/binop-select-cast-of-select-cond.ll