]> git.ipfire.org Git - thirdparty/gcc.git/commit
ivopts: Change constant_multiple_of to expand aff nodes.
authorAlfie Richards <alfie.richards@arm.com>
Tue, 24 Jun 2025 13:49:27 +0000 (13:49 +0000)
committerAlfie Richards <alfie.richards@arm.com>
Wed, 25 Jun 2025 12:25:11 +0000 (12:25 +0000)
commite7ff8e8d77df7407e075f1c0cede5c97cda5eba7
tree75d1a8ddf15a3d70af048776bfc2b51de6ae6f51
parent1bac0fcd04662138f0a91057914a1be420cb92d5
ivopts: Change constant_multiple_of to expand aff nodes.

This changes the calls to tree_to_aff_combination in constant_multiple_of to
tree_to_aff_combination_expand along with associated plumbing of ivopts_data
and required cache.

This improves cases such as:

```c
void f(int *p1, int *p2, unsigned long step, unsigned long end, svbool_t pg) {
    for (unsigned long i = 0; i < end; i += step) {
        svst1(pg, p1, svld1_s32(pg, p2));
        p1 += step;
        p2 += step;
    }
}
```

Where ivopts previously didn't expand the SSA variables for the step increements
and so lacked the ability to group all the IV's and ended up with:

```
f:
cbz x3, .L1
mov x4, 0
.L3:
ld1w z31.s, p0/z, [x1]
add x4, x4, x2
st1w z31.s, p0, [x0]
add x1, x1, x2, lsl 2
add x0, x0, x2, lsl 2
cmp x3, x4
bhi .L3
.L1:
ret
```

After this change we end up with:

```
f:
cbz x3, .L1
mov x4, 0
.L3:
ld1w z31.s, p0/z, [x1, x4, lsl 2]
st1w z31.s, p0, [x0, x4, lsl 2]
add x4, x4, x2
cmp x3, x4
bhi .L3
.L1:
ret
```

gcc/ChangeLog:

* tree-ssa-loop-ivopts.cc (constant_multiple_of): Change
tree_to_aff_combination to tree_to_aff_combination_expand and add
parameter to take ivopts_data.
(get_computation_aff_1): Change parameters and calls to include
ivopts_data.
(get_computation_aff): Ditto.
(get_computation_at) Ditto.:
(get_debug_computation_at) Ditto.:
(get_computation_cost) Ditto.:
(rewrite_use_nonlinear_expr) Ditto.:
(rewrite_use_address) Ditto.:
(rewrite_use_compare) Ditto.:
(remove_unused_ivs) Ditto.:

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/adr_7.c: New test.
gcc/testsuite/gcc.target/aarch64/sve/adr_7.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.cc