[RISCV] Fold (add (select lhs, rhs, cc, 0, y), x) -> (select lhs, rhs, cc, x, (add...
authorCraig Topper <craig.topper@sifive.com>
Tue, 10 Aug 2021 15:27:34 +0000 (08:27 -0700)
committerCraig Topper <craig.topper@sifive.com>
Tue, 10 Aug 2021 16:02:56 +0000 (09:02 -0700)
commit6f5edc3487948ca7f25118e693344f41a95a8ca1
treea02c59f83aa8976cabee8cc719205868fe4e5710
parentce96d81c471e678f4b73bccd2553aae45d066457
[RISCV] Fold (add (select lhs, rhs, cc, 0, y), x) -> (select lhs, rhs, cc, x, (add x, y))

Similar for sub except sub isn't commutative.

Modify the existing and/or/xor folds to also work on ISD::SELECT
and not just RISCVISD::SELECT_CC. This is needed to make sure
we do this transform before type legalization turns i32 add/sub
into add/sub+sign_extend_inreg on RV64. If we don't do this before
that, the sign_extend_inreg will still be after the select.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D107603
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rv32zbs.ll
llvm/test/CodeGen/RISCV/select-binop-identity.ll