public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/65946] New: Simple loop with if-statement not vectorized
@ 2015-04-30 12:00 alalaw01 at gcc dot gnu.org
  2015-04-30 12:02 ` [Bug middle-end/65946] " alalaw01 at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: alalaw01 at gcc dot gnu.org @ 2015-04-30 12:00 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug middle-end/65946] Simple loop with if-statement not vectorized
  2015-04-30 12:00 [Bug middle-end/65946] New: Simple loop with if-statement not vectorized alalaw01 at gcc dot gnu.org
@ 2015-04-30 12:02 ` alalaw01 at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: alalaw01 at gcc dot gnu.org @ 2015-04-30 12:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65946

alalaw01 at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-04-30
           Assignee|unassigned at gcc dot gnu.org      |alalaw01 at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from alalaw01 at gcc dot gnu.org ---
Discussion here: https://gcc.gnu.org/ml/gcc/2015-04/msg00351.html

Suggestion is to use loop-header-copying to rotate the loop to a form that both
if-conversion and the vectorizer can handle.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-30 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-30 12:00 [Bug middle-end/65946] New: Simple loop with if-statement not vectorized alalaw01 at gcc dot gnu.org
2015-04-30 12:02 ` [Bug middle-end/65946] " alalaw01 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).