This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/65946] New: Simple loop with if-statement not vectorized
- From: "alalaw01 at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 30 Apr 2015 12:00:44 +0000
- Subject: [Bug middle-end/65946] New: Simple loop with if-statement not vectorized
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65946
Bug ID: 65946
Summary: Simple loop with if-statement not vectorized
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: alalaw01 at gcc dot gnu.org
Target Milestone: ---
Target: x86_64
This testcase:
#define N 32
int a[N], b[N];
int
foo ()
{
for (int i = 0; i < N ; i++)
{
int m = (a[i] & i) ? 5 : 4;
b[i] = a[i] * m;
}
}
does not vectorize at -O3 on x86_64 or other platforms. Following dom1, jump
threading partially peels the loop to give:
<bb 2>:
goto <bb 8>;
<bb 3>:
# i_11 = PHI <i_9(6)>
_5 = a[i_11];
_6 = i_11 & _5;
if (_6 != 0)
goto <bb 4>;
else
goto <bb 5>;
<bb 4>:
<bb 5>:
# m_14 = PHI <5(4), 4(3)>
<bb 6>:
# m_2 = PHI <m_14(5), 4(8)>
# _15 = PHI <_5(5), _10(8)>
# i_16 = PHI <i_11(5), i_1(8)>
_7 = m_2 * _15;
b[i_16] = _7;
i_9 = i_16 + 1;
if (i_9 != 32)
goto <bb 3>;
else
goto <bb 7>;
<bb 7>:
return;
<bb 8>:
# i_1 = PHI <0(2)>
_10 = a[i_1];
_3 = i_1 & _10;
goto <bb 6>;
which form cannot be if-converted (tree-if-conv.c):
/* If one of the loop header's edge is an exit edge then do not
apply if-conversion. */
FOR_EACH_EDGE (e, ei, loop->header->succs)
if (loop_exit_edge_p (loop, e))
return false;
and even if it were, the PHI nodes at loop entry cannot be handled by the
vectorizer.