[RISCV] Add DAG combine to detect opportunities to replace (i64 (any_extend (i32...
authorCraig Topper <craig.topper@sifive.com>
Fri, 25 Jun 2021 19:58:31 +0000 (12:58 -0700)
committerCraig Topper <craig.topper@sifive.com>
Sat, 26 Jun 2021 06:16:37 +0000 (23:16 -0700)
commitd4f4a1ba626d7c3e4442d6f68feb79d56eba9601
tree8af79e2055fe6763d68bc401fd8eddb8db7de2ec
parent043ce4e6bdd376ff460d78446d1a6b94c6e0f18c
[RISCV] Add DAG combine to detect opportunities to replace (i64 (any_extend (i32 X)) with sign_extend.

If type legalization is going to insert a sign_extend for other users
of X and we can fold the sign_extend into ADDW/MULW/SUBW, it is
better to replace the ANY_EXTEND so we don't end up with a separate
ADD/MUL/SUB instruction for the users of the ANY_EXTEND.

I'm only handling setcc uses right now, but there are other
instructions that force sign_extends like ashr.

There are probably other *W instructions we could use in addition
to ADDW/SUBW/MULW.

My motivating case was a loop terminating compare and a phi use
as seen in the new test file.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D104581
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/aext-to-sext.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/rv64zbb.ll