[RISCV] Custom type legalize i32 ISD::ABS on RV64 without Zbb.
authorCraig Topper <craig.topper@sifive.com>
Mon, 28 Feb 2022 17:30:27 +0000 (09:30 -0800)
committerCraig Topper <craig.topper@sifive.com>
Mon, 28 Feb 2022 17:30:27 +0000 (09:30 -0800)
commitf46890711f03dfb02722ec18dc332753967700e8
treeaf1c7baec8763cad57f98dda106bed3186ef331c
parentd3db74eadbfc06425668b39c41eeeca22f747978
[RISCV] Custom type legalize i32 ISD::ABS on RV64 without Zbb.

Default type legalization will create sext_inreg+abs, but we may
not be able to remove the sext_inreg.

Instead this patch expands abs during type legalization to
Y = sraiw X, 31; subw(xor X, Y), Y) which doesn't require the input
to be sign extended.

This gives a big improvement for some neg-abs tests where the
abs is used more than the the neg. Previously the abs was expanded
a different way before and after type legalization. Now they are
expanded in a similar way enabling more CSE.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D120636
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/neg-abs.ll
llvm/test/CodeGen/RISCV/rv64zbb.ll