[RISCV] Sign extend constant arguments to V intrinsics when promoting to XLen.
authorCraig Topper <craig.topper@sifive.com>
Fri, 18 Dec 2020 19:22:43 +0000 (11:22 -0800)
committerCraig Topper <craig.topper@sifive.com>
Fri, 18 Dec 2020 19:43:38 +0000 (11:43 -0800)
commit09468a914827b33fe6fe1fcf05ba87c60709d49d
tree01b4ef6526e31c1445d6d8088fe180a3a9358c1f
parent1f1145006b32533484c9ebc0f45e241a02fe6c8b
[RISCV] Sign extend constant arguments to V intrinsics when promoting to XLen.

The default behavior for any_extend of a constant is to zero extend.
This occurs inside of getNode rather than allowing type legalization
to promote the constant which would sign extend. By using sign extend
with getNode the constant will be sign extended. This gives a better
chance for isel to find a simm5 immediate since all xlen bits are
examined there.

For instructions that use a uimm5 immediate, this change only affects
constants >= 128 for i8 or >= 32768 for i16. Constants that large
already wouldn't have been eligible for uimm5 and would need to use a
scalar register.

If the instruction isn't able to use simm5 or the immediate is
too large, we'll need to materialize the immediate in a register.
As far as I know constants with all 1s in the upper bits should
materialize as well or better than all 0s.

Longer term we should probably have a SEW aware PatFrag to ignore
the bits above SEW before checking simm5.

I updated about half the test cases in some tests to use a negative
constant to get coverage for this.

Reviewed By: evandro

Differential Revision: https://reviews.llvm.org/D93487
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/vadc-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vadc-rv64.ll
llvm/test/CodeGen/RISCV/rvv/vadd-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vmadc-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vmadc-rv64.ll
llvm/test/CodeGen/RISCV/rvv/vmadc.carry.in-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vrsub-rv32.ll