[RISCV] Fold binary op into select if profitable.
authorMikhail Gudim <mgudim@gmail.com>
Mon, 12 Jun 2023 15:15:15 +0000 (11:15 -0400)
committerMikhail Gudim <mgudim@gmail.com>
Mon, 12 Jun 2023 18:19:12 +0000 (14:19 -0400)
commitd0189584631e587279ee5f0af5feb94d8045bb31
tree1e4a6a6617f2253e8d54b75080a76b217e3cb308
parent99686c5ed1784c47040a740377c1f4d15b058d87
[RISCV] Fold binary op into select if profitable.

Consider the following pattern `binOp (select cond, x, c0), c1`.
Where `c0` and `c1` are constants.
We can transform it to `select cond, binOp(x, c1), binOp(c0, c1)`.

If `binOp(c0, c1)` ends up being `0` or `-1` we can turn the select into
a more profitable sequence.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/fold-binop-into-select.ll [new file with mode: 0644]