]> git.ipfire.org Git - thirdparty/gcc.git/commit
vect: Add pattern recognition for vectorizing {FLOOR,CEIL,ROUND}_{MOD, DIV}_EXPR
authorAvinash Jayakar <avinashd@linux.ibm.com>
Fri, 17 Oct 2025 07:08:59 +0000 (12:38 +0530)
committerAvinash Jayakar <avinashd@linux.ibm.com>
Fri, 17 Oct 2025 07:41:44 +0000 (13:11 +0530)
commit6883d51304f1aa852da3f2b4eb26bdf2e12bbcb9
tree08f9053440411f71fe9062a9a1351ff66d833290
parenteb717a8f4ea9f5eebb3d5add0ca4a33d74febd1a
vect: Add pattern recognition for vectorizing {FLOOR,CEIL,ROUND}_{MOD, DIV}_EXPR

Added a new helper function "add_code_for_floorceilround_divmod" in
tree-vect-patterns.cc for adding compensating code for each of the op
{FLOOR,ROUND,CEIL}_{DIV,MOD}_EXPR. This function checks if target supports all
required operations required to implement these operation and generates
vectorized code for the respective operations. Based on the following logic
FLOOR_{DIV,MOD}
r = x %[fl] y;
r = x % y; if (r && (x ^ y) < 0) r += y;
r = x/[fl] y;
r = x % y; d = x/y; if (r && (x ^ y) < 0) d--;
CEIL_{DIV,MOD} (unsigned)
r = x %[cl] y;
r = x % y; if (r) r -= y;
r = x/[cl] y;
r = x % y; d = x/y; if (r) d++;
CEIL_{DIV,MOD} (signed)
r = x %[cl] y;
r = x % y; if (r && (x ^ y) >= 0) r -= y;
r = x/[cl] y;
r = x % y; d = x/y; if (r && (x ^ y) >= 0) d++;
ROUND_{DIV,MOD} (unsigned)
r = x %[rd] y;
r = x % y; if (r > ((y-1)/2)) r -= y;
r = x/[rd] y;
r = x % y; d = x/y; if (r > ((y-1)/2)) d++;
ROUND_{DIV,MOD} (signed)
r = x %[rd] y;
r = x % y; if (r > ((y-1)/2))
{if ((x ^ y) >= 0) r -= y; else r += y;}
r = x/[rd] y;
r = x % y; d = x/y; if ((r > ((y-1)/2)) && (x ^ y) >= 0)
{if ((x ^ y) >= 0) d++; else d--;}
each of the case is implemented in a vectorized form.
This function is then called in each of the path in vect_recog_divmod_pattern,
which there are 3, based on value of constant operand1,
1. == 2
2. == power of 2
3. otherwise

2025-10-17  Avinash Jayakar  <avinashd@linux.ibm.com>

gcc/ChangeLog:
PR tree-optimization/104116
* tree-vect-patterns.cc (add_code_for_floorceilround_divmod): patt recog
for {FLOOR,ROUND,CEIL}_{DIV,MOD}_EXPR.
(vect_recog_divmod_pattern): Call add_code_for_floorceilround_divmod
after computing div/mod for each control path.

gcc/testsuite/ChangeLog:
PR tree-optimization/104116
* gcc.dg/vect/pr104116-ceil-div-2.c: New test.
* gcc.dg/vect/pr104116-ceil-div-pow2.c: New test.
* gcc.dg/vect/pr104116-ceil-div.c: New test.
* gcc.dg/vect/pr104116-ceil-mod-2.c: New test.
* gcc.dg/vect/pr104116-ceil-mod-pow2.c: New test.
* gcc.dg/vect/pr104116-ceil-mod.c: New test.
* gcc.dg/vect/pr104116-ceil-udiv-2.c: New test.
* gcc.dg/vect/pr104116-ceil-udiv-pow2.c: New test.
* gcc.dg/vect/pr104116-ceil-udiv.c: New test.
* gcc.dg/vect/pr104116-ceil-umod-2.c: New test.
* gcc.dg/vect/pr104116-ceil-umod-pow2.c: New test.
* gcc.dg/vect/pr104116-ceil-umod.c: New test.
* gcc.dg/vect/pr104116-floor-div-2.c: New test.
* gcc.dg/vect/pr104116-floor-div-pow2.c: New test.
* gcc.dg/vect/pr104116-floor-div.c: New test.
* gcc.dg/vect/pr104116-floor-mod-2.c: New test.
* gcc.dg/vect/pr104116-floor-mod-pow2.c: New test.
* gcc.dg/vect/pr104116-floor-mod.c: New test.
* gcc.dg/vect/pr104116-round-div-2.c: New test.
* gcc.dg/vect/pr104116-round-div-pow2.c: New test.
* gcc.dg/vect/pr104116-round-div.c: New test.
* gcc.dg/vect/pr104116-round-mod-2.c: New test.
* gcc.dg/vect/pr104116-round-mod-pow2.c: New test.
* gcc.dg/vect/pr104116-round-mod.c: New test.
* gcc.dg/vect/pr104116-round-udiv-2.c: New test.
* gcc.dg/vect/pr104116-round-udiv-pow2.c: New test.
* gcc.dg/vect/pr104116-round-udiv.c: New test.
* gcc.dg/vect/pr104116-round-umod-2.c: New test.
* gcc.dg/vect/pr104116-round-umod-pow2.c: New test.
* gcc.dg/vect/pr104116-round-umod.c: New test.
* gcc.dg/vect/pr104116.h: New test.
32 files changed:
gcc/testsuite/gcc.dg/vect/pr104116-ceil-div-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-div-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-div.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-mod-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-mod-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-mod.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-udiv-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-udiv-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-udiv.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-umod-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-umod-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-ceil-umod.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-floor-div-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-floor-div-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-floor-div.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-floor-mod-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-floor-mod-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-floor-mod.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-div-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-div-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-div.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-mod-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-mod-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-mod.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-udiv-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-udiv-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-udiv.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-umod-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-umod-pow2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116-round-umod.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr104116.h [new file with mode: 0644]
gcc/tree-vect-patterns.cc