[RISCV] Custom type legalize i32 loads by sign extending.
authorCraig Topper <craig.topper@sifive.com>
Mon, 12 Sep 2022 16:12:56 +0000 (09:12 -0700)
committerCraig Topper <craig.topper@sifive.com>
Mon, 12 Sep 2022 16:13:07 +0000 (09:13 -0700)
commit4186a49d793eb69afee7a724dad87a8ecd434e51
tree7ed0c56c22806de8c4ca3c0cc4b5ee9bdf3ec3cb
parentc1502425ba2d10d75c35e8c00a29aabd8c8e59ba
[RISCV] Custom type legalize i32 loads by sign extending.

The default is to use extload which can become a zextload or
sextload if it is followed by an 'and' or sext_inreg.

Sometimes type legalization will introduce an 'and' from promoting
something like 'srl X, C' and a sext_inreg from from a setcc. The
'and' could be freely folded with the promoted 'srl' by using srliw,
but the sext_inreg can't be folded into a compare. DAG combiner
will see both of these choices and may decide to fold the 'and'
instead of the 'sext_inreg'. This forces the sext_inreg to become
a sext.w.

By picking sextload in the type legalizer we take this choice away.
Looking at spec2006 compiled with Zba and Zbb this appeared to be
net reduction in lines of code in the objdump disassembly output.

This is similar to what we do with i32 add/sub/mul/shl in
type legalization where we always emit a sext_inreg.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D130397
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/sextw-removal.ll
llvm/test/CodeGen/RISCV/vec3-setcc-crash.ll