]> git.ipfire.org Git - thirdparty/gcc.git/commit
Match: Add int type fits check for form 2 of .SAT_SUB imm operand
authorPan Li <pan2.li@intel.com>
Mon, 2 Sep 2024 03:33:08 +0000 (11:33 +0800)
committerPan Li <pan2.li@intel.com>
Fri, 6 Sep 2024 02:26:06 +0000 (10:26 +0800)
commita2e28b105cea4c44c3903d8d979c7a4afa1193f0
treeb244f4bd70014eab744563952c60f66483282617
parent019335b404c8d7fb2d234bb179745cc28693dd20
Match: Add int type fits check for form 2 of .SAT_SUB imm operand

This patch would like to add strict check for imm operand of .SAT_SUB
matching.  We have no type checking for imm operand in previous, which
may result in unexpected IL to be catched by .SAT_SUB pattern.

We leverage the int_fits_type_p here to make sure the imm operand is
a int type fits the result type of the .SAT_SUB.  For example:

Fits uint8_t:
uint8_t a;
uint8_t sum = .SAT_SUB (a, 12);
uint8_t sum = .SAT_SUB (a, 12u);
uint8_t sum = .SAT_SUB (a, 126u);
uint8_t sum = .SAT_SUB (a, 128u);
uint8_t sum = .SAT_SUB (a, 228);
uint8_t sum = .SAT_SUB (a, 223u);

Not fits uint8_t:
uint8_t a;
uint8_t sum = .SAT_SUB (a, -1);
uint8_t sum = .SAT_SUB (a, 256u);
uint8_t sum = .SAT_SUB (a, 257);

The below test suite are passed for this patch:
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

* match.pd: Add int_fits_type_p check for .SAT_SUB imm operand.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_u_add_imm_type_check-57.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-58.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-59.c: New test.
* gcc.target/riscv/sat_u_add_imm_type_check-60.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/match.pd
gcc/testsuite/gcc.target/riscv/sat_arith.h
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-57.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-58.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-59.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-60.c [new file with mode: 0644]