https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121383
Bug ID: 121383
Summary: if-convert lacks support for && conditions
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: tnfchris at gcc dot gnu.org
Reporter: tnfchris at gcc dot gnu.org
Blocks: 53947, 115130
Target Milestone: ---
The following example loop:
#define N 1000
int a[N] = {0};
int b[N] = {0};
int c[N] = {0};
__attribute__((noipa, noinline))
int foo ()
{
for (int i = 0; i < N; i++)
{
if (a[i] > b[i] && a[i] > c[i])
return 1;
}
return 0;
}
fails to vectorize because the && conditions create an in-vector loop control
flow block layout that we don't support:
example.c:9:21: note: using as main loop exit: 5 -> 11 [AUX: (nil)]
example.c:9:21: missed: not vectorized: unsupported control flow in loop.
example.c:9:21: missed: bad loop form.
example.c:9:21: missed: couldn't vectorize loop
example.c:9:21: missed: not vectorized: unsupported control flow in loop.
example.c:7:5: note: vectorized 0 loops in function.
The first block on it's own is not an exit and so we bail out.
The primary reason for this is that if-convert lacks support for early exit
loops as we've never added it. ifcvt reports:
Can not ifcvt due to multiple exits
Analyzing loop 1 for bitfields:
due to the block
/* More than one loop exit is too much to handle. */
if (!single_exit (loop))
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Can not ifcvt due to multiple exits\n");
}
This blocks vectorization of the remaining hot loop in 523.xalancbmk_r in
SPECCPU2017.
Biggest obstacle to supporting this is combine_blocks which atm seems to want
to merge into a fixed block containing the
latch exit condition.
The alignment constraints on the memrefs for speculative loads should allow us
to merge the blocks and perform the loads earlier.
Mine.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115130
[Bug 115130] [meta-bug] early break vectorization