[RISCV] Fold (RISCVISD::SELECT_CC X, Y, CC, Z, Z) -> Z.
authorCraig Topper <craig.topper@sifive.com>
Wed, 1 Sep 2021 19:11:37 +0000 (12:11 -0700)
committerCraig Topper <craig.topper@sifive.com>
Wed, 1 Sep 2021 19:37:52 +0000 (12:37 -0700)
commitccbb4c8b4ffd00588f0c21c7e5208bf210b26a53
tree8033a131e4ccf421cd6079ed92be5e8febcb7987
parentb0fdbadf9f099e42bd2185ed32211b2d73cb2f58
[RISCV] Fold (RISCVISD::SELECT_CC X, Y, CC, Z, Z) -> Z.

If the true and false values are the same, we don't need a SELECT_CC.

This would normally be folded before a select is legalized to
select_cc. The test case exploits the late legalization of vscale
to trigger a case where they become identical after legalization.

This works around an issue found on a test case in D107957. In that
case the true/false values were both eventually 0 and the select was
used by a vector AVL operand. The select_cc got expanded to control
flow and a phi, but the phi inputs were both copies from X0. MachineIR
optimizations simplified this to a single copy from X0 going into the
vector instruction. This became the input of a vsetvli after vsetvli
insertion. Then register coalescing folded the copy into the vsetvli.
X0 as the source of a vsetvli is a special encoding and should not be
created by coalesing. We need to fix our vsetvli handling to make sure
this can never happen any other way, but removing the unneeded select
is still a worthwhile optimization.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/rvv-vscale.i64.ll