diff options
author | Pan Li <pan2.li@intel.com> | 2025-01-23 12:14:43 +0800 |
---|---|---|
committer | Pan Li <pan2.li@intel.com> | 2025-01-29 17:36:46 +0800 |
commit | bfb57d62c743235284f9b31a88c6ceed9971d27a (patch) | |
tree | 0fd6ac516227ca2d46eb6f47050eab9f748581e1 /gcc/expr.cc | |
parent | 81aa9488321dea5ed1d55d0dfb1a72f362a1a24f (diff) | |
download | gcc-bfb57d62c743235284f9b31a88c6ceed9971d27a.zip gcc-bfb57d62c743235284f9b31a88c6ceed9971d27a.tar.gz gcc-bfb57d62c743235284f9b31a88c6ceed9971d27a.tar.bz2 |
RISC-V: Fix incorrect code gen for scalar signed SAT_SUB [PR117688]
This patch would like to fix the wroing code generation for the scalar
signed SAT_SUB. The input can be QI/HI/SI/DI while the alu like sub
can only work on Xmode. Unfortunately we don't have sub/add for
non-Xmode like QImode in scalar, thus we need to sign extend to Xmode
to ensure we have the correct value before ALU like sub. The gen_lowpart
will generate something like lbu which has all zero for highest bits.
For example, when 0xff(-1 for QImode) sub 0x1(1 for QImode), we actually
want to -1 - 1 = -2, but if there is no sign extend like lbu, we will get
0xff - 1 = 0xfe which is incorrect. Thus, we have to sign extend 0xff(Qmode)
to 0xffffffffffffffff(assume XImode is DImode) before sub in Xmode.
The below test suites are passed for this patch.
* The rv64gcv fully regression test.
PR target/117688
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_expand_sssub): Leverage the helper
riscv_extend_to_xmode_reg with SIGN_EXTEND.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/pr117688.h: Add test helper macro.
* gcc.target/riscv/pr117688-sub-run-1-s16.c: New test.
* gcc.target/riscv/pr117688-sub-run-1-s32.c: New test.
* gcc.target/riscv/pr117688-sub-run-1-s64.c: New test.
* gcc.target/riscv/pr117688-sub-run-1-s8.c: New test.
Signed-off-by: Pan Li <pan2.li@intel.com>
Diffstat (limited to 'gcc/expr.cc')
0 files changed, 0 insertions, 0 deletions