There's a pass ordering issue between the sink pass and tree-if-conv, if conversion for vectorization. When sink sinks a possibly trapping operation to a place that is only conditionally executed if-conversion fails which results in failed vectorization. This can be seen with https://gcc.gnu.org/pipermail/gcc-patches/2020-May/545588.html applied for gcc.dg/vect/pr56541.c (and it's ifcvt counterpart gcc.dg/tree-ssa/ifc-pr56541.c). But I've also seen this in other context. Here iftmp.2_17 = rR_19 < rL_20 ? rR_19 : rL_20; iftmp.3_3 = rR_19 < rL_20 ? rL_20 : rR_19; if (iftmp.3_3 > 0.0) goto <bb 5>; [INV] else goto <bb 4>; [INV] <bb 4> : <bb 5> : # iftmp.4_14 = PHI <iftmp.2_17(3), 1.5e+2(4)> if (iftmp.4_14 > 0.0) becomes iftmp.3_3 = rR_17 < rL_18 ? rL_18 : rR_17; if (iftmp.3_3 > 0.0) goto <bb 4>; [59.00%] else goto <bb 9>; [41.00%] <bb 9> [local count: 435831803]: goto <bb 6>; [100.00%] <bb 4> [local count: 627172605]: iftmp.2_15 = rR_17 < rL_18 ? rR_17 : rL_18; if (iftmp.2_15 > 0.0) and the now conditionally executed FP comparison can trap.
Yeah. I'm seeing this as a GCC 11/12 regression on: float f(float *x, float *y) { float res = 0; for (int i = 0; i < 100; ++i) { float next = __builtin_sqrtf (y[i]); res += x[i] < 100 ? x[i] : next; } return res; } which is cut down from HACCmk. Previously we could vectorise the loop for Advanced SIMD at -Ofast, whereas now we require -Ofast -fno-tree-sink. (SVE can vectorise it both ways due to predicated loads.)
Note the issue is older but there are some cases where sink didn't do its job that have been fixed meanwhile. For GCC 12 we have an additional (albeit quite late) sinking pass, so one option might be to tame down early sinking for possibly trapping operations in loops that look like they could be vectorized (similar how we tame PRE). I think the only loop pass affected by not sinking might be unswitching which could get less favorable costs due to the need to duplicate the not sunk stmts. At least I cannot think of a way to preserve the conditional non-trappingness on the ref after sinking it.
GCC 11.3 is being released, retargeting bugs to GCC 11.4.
*** Bug 106217 has been marked as a duplicate of this bug. ***
GCC 11.4 is being released, retargeting bugs to GCC 11.5.
This was fixed by the patch which fixed PR 92335 and since that is still open as a regression like this one I am going to close this one as a dup of bug 92335 and they are exactly the same issue even. *** This bug has been marked as a duplicate of bug 92335 ***