https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116776
Bug ID: 116776
Summary: Complex if conditions not hoisted from loop
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: matmal01 at gcc dot gnu.org
Target Milestone: ---
The condition in the following loop does not get hoisted at `-O3` on GCC trunk.
Simplifying the condition (by either removing some of the `shouldthischange`
checks, or simplifying the `shouldthischange` function) allows hoisting.
N.b. Some of the condition gets hoisted, just not all.
N.b. having the condition inside the loop blocks vectorisation when compiled
with `-march=armv8.6-a+sve+sve2`.
```
struct teststruct {
unsigned long dims[2];
double *data;
bool ** allocated;
};
bool shouldthischange(struct teststruct *v, int b, int l) {
return
// true ||
v->dims[1] > l
&& v->allocated[b][l]
;
}
void DoLoop(struct teststruct *x, struct teststruct *y, struct teststruct *z,
unsigned long len)
{
for (unsigned long i = 0; i < len; i++)
if (shouldthischange(x, 0, 0) && shouldthischange(y, 0, 0) &&
shouldthischange(z, 0, 0)) {
z->data[i] = x->data[i] + y->data[i];
}
}
```