On 9/1/24 11:52 PM, pan2...@intel.com wrote:
From: Pan Li <pan2...@intel.com>

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 (12, a);
uint8_t sum = .SAT_SUB (12u, a);
uint8_t sum = .SAT_SUB (126u, a);
uint8_t sum = .SAT_SUB (128u, a);
uint8_t sum = .SAT_SUB (228, a);
uint8_t sum = .SAT_SUB (223u, a);

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

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-53.c: New test.
        * gcc.target/riscv/sat_u_add_imm_type_check-54.c: New test.
        * gcc.target/riscv/sat_u_add_imm_type_check-55.c: New test.
        * gcc.target/riscv/sat_u_add_imm_type_check-56.c: New test.
Testsuite bits are fine for both patches in this series.

match.pd bits are fine as well if nobody objects in 48hrs.

jeff

Reply via email to