]> git.ipfire.org Git - thirdparty/gcc.git/commit
Match: Add int type fits check for form 1 of .SAT_SUB imm operand
authorPan Li <pan2.li@intel.com>
Mon, 2 Sep 2024 01:48:46 +0000 (09:48 +0800)
committerPan Li <pan2.li@intel.com>
Fri, 6 Sep 2024 02:26:01 +0000 (10:26 +0800)
commit019335b404c8d7fb2d234bb179745cc28693dd20
tree745645560d04a81703bb209b23f497cfa5282fa1
parentead5f587dad3206e45db7ac31f5c34c1530ae529
Match: Add int type fits check for form 1 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 (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.

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-53.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-54.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-55.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/sat_u_add_imm_type_check-56.c [new file with mode: 0644]