[RISCV] Optimize multiplication with immediates
authorBen Shi <powerman1st@163.com>
Sat, 15 Apr 2023 09:10:06 +0000 (17:10 +0800)
committerBen Shi <powerman1st@163.com>
Sat, 15 Apr 2023 09:29:06 +0000 (17:29 +0800)
commit2e43eea2da4ec9d2e8f9ce2fd8fae0c034d2465a
treea15043095d56e7169de468fc10474282cb3cab56
parentaa1642f6cc4ac8403b21f998a1234bea2948ac9d
[RISCV] Optimize multiplication with immediates

The optimization of (mul x, c) to (ADD (SLLI x, i0), (SLLI x, i1))
is only enabled for i32 multiplication on rv64, because of
the regression in i64 multiplication on rv32.

However we can change the condition to that the immediate 'c'
should only be used once, then the above regression can also be
avoided, and ohter chances of optimization can be enabled.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D147410
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/mul.ll
llvm/test/CodeGen/RISCV/rv32zba.ll
llvm/test/CodeGen/RISCV/rv64zba.ll