diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2024-10-24 14:22:31 +0100 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2024-10-24 14:22:31 +0100 |
commit | e2e798b86074010a8d5da16ce0b199fcec70a50e (patch) | |
tree | f949a8fb5ca94812d1dded54ebbe591011ee9eb6 /gcc/testsuite | |
parent | 3e93828e601c62176ea2b4a1dd0b5a1db5657a8e (diff) | |
download | gcc-e2e798b86074010a8d5da16ce0b199fcec70a50e.zip gcc-e2e798b86074010a8d5da16ce0b199fcec70a50e.tar.gz gcc-e2e798b86074010a8d5da16ce0b199fcec70a50e.tar.bz2 |
Use get_nonzero_bits to simplify trunc_div to exact_div
There are a limited number of existing rules that benefit from
knowing that a division is exact. Later patches will add more.
gcc/
* match.pd: Simplify X / (1 << C) to X /[ex] (1 << C) if the
low C bits of X are clear
gcc/testsuite/
* gcc.dg/tree-ssa/cmpexactdiv-6.c: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-6.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-6.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-6.c new file mode 100644 index 0000000..82d517b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-6.c @@ -0,0 +1,29 @@ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ + +typedef __INTPTR_TYPE__ intptr_t; + +int +f1 (int x, int y) +{ + if ((x & 1) || (y & 1)) + __builtin_unreachable (); + x /= 2; + y /= 2; + return x < y; +} + +int +f2 (void *ptr1, void *ptr2, void *ptr3) +{ + ptr1 = __builtin_assume_aligned (ptr1, 4); + ptr2 = __builtin_assume_aligned (ptr2, 4); + ptr3 = __builtin_assume_aligned (ptr3, 4); + intptr_t diff1 = (intptr_t) ptr1 - (intptr_t) ptr2; + intptr_t diff2 = (intptr_t) ptr1 - (intptr_t) ptr3; + diff1 /= 2; + diff2 /= 2; + return diff1 < diff2; +} + +/* { dg-final { scan-tree-dump-not {<[a-z]*_div_expr,} "optimized" } } */ +/* { dg-final { scan-tree-dump-not {<rshift_expr,} "optimized" } } */ |