public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop
@ 2012-04-04 13:26 izamyatin at gmail dot com
  2012-04-04 13:27 ` [Bug fortran/52865] " izamyatin at gmail dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: izamyatin at gmail dot com @ 2012-04-04 13:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

             Bug #: 52865
           Summary: GCC can't vectorize fortran loop but able to vectorize
                    similar c-loop
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: izamyatin@gmail.com
            Target: x86-64


Created attachment 27087
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27087
Fortran test

That looks strange but the compiler behaves differently on O3 for attached test
cases. 
Fortran can't vectorize loop which looks quite simple

Is it expected behavior?


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
@ 2012-04-04 13:27 ` izamyatin at gmail dot com
  2012-04-04 13:50 ` rguenth at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: izamyatin at gmail dot com @ 2012-04-04 13:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #1 from Igor Zamyatin <izamyatin at gmail dot com> 2012-04-04 13:27:11 UTC ---
Created attachment 27088
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27088
C test


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
  2012-04-04 13:27 ` [Bug fortran/52865] " izamyatin at gmail dot com
@ 2012-04-04 13:50 ` rguenth at gcc dot gnu.org
  2012-04-04 14:00 ` [Bug tree-optimization/52865] " burnus at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-04 13:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-04 13:49:38 UTC ---
DOUBLE PRECISION Dx(*) , Dy(*)

and

double X[1000], Y[1000]

are not at all the same.


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

* [Bug tree-optimization/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
  2012-04-04 13:27 ` [Bug fortran/52865] " izamyatin at gmail dot com
  2012-04-04 13:50 ` rguenth at gcc dot gnu.org
@ 2012-04-04 14:00 ` burnus at gcc dot gnu.org
  2012-04-04 14:26 ` burnus at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-04-04 14:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
                 CC|                            |burnus at gcc dot gnu.org
          Component|fortran                     |tree-optimization

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-04-04 14:00:30 UTC ---
(In reply to comment #2)
>   DOUBLE PRECISION Dx(*) , Dy(*)
> and
>   double X[1000], Y[1000]
> are not at all the same.

But one still gets the same result if one uses:

  void daxpy(int m, int n, double X[], double Y[], double z)

which should be close to what one gets with Fortran.


 * * *

For the Fortran loop, -ftree-vectorizer-verbose=3 shows:

14: ===== analyze_loop_nest =====
14: === vect_analyze_loop_form ===
14: not vectorized: unexpected loop form.
14: bad loop form.


For the C loop:
6: Profitability threshold is 2 loop iterations.
6: created 1 versioning for alias checks.
6: vectorizing stmts using SLP.
6: LOOP VECTORIZED.


For the Fortran loop, using ifort 12.1:
(15): (col. 19) remark: BLOCK WAS VECTORIZED.
(14): (col. 16) remark: loop was not vectorized: not inner loop.



Original dump for the Fortran loop (-fdump-tree-original):

    D.1862 = mp1;
    D.1863 = *n;
    i = D.1862;
    if (D.1863 < D.1862) goto L.2;
    countm1.0 = (unsigned int) (NON_LVALUE_EXPR <D.1863>
                                - NON_LVALUE_EXPR <D.1862>) / 4;
    while (1)
      {
        (*dy)[(integer(kind=8)) i + -1] = (*dy)[(integer(kind=8)) i + -1]
                                  + *da * (*dx)[(integer(kind=8)) i + -1];
        (*dy)[(integer(kind=8)) (i + 1) + -1]
                   = (*dy)[(integer(kind=8)) (i + 1) + -1]
             + *da * (*dx)[(integer(kind=8)) (i + 1) + -1];
        (*dy)[(integer(kind=8)) (i + 2) + -1]
                   = (*dy)[(integer(kind=8)) (i + 2) + -1]
             + *da * (*dx)[(integer(kind=8)) (i + 2) + -1];
        (*dy)[(integer(kind=8)) (i + 3) + -1]
                   = (*dy)[(integer(kind=8)) (i + 3) + -1]
             + *da * (*dx)[(integer(kind=8)) (i + 3) + -1];
        L.1:;
        i = i + 4;
        if (countm1.0 == 0) goto L.2;
        countm1.0 = countm1.0 + 4294967295;
      }
    L.2:;


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

* [Bug tree-optimization/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (2 preceding siblings ...)
  2012-04-04 14:00 ` [Bug tree-optimization/52865] " burnus at gcc dot gnu.org
@ 2012-04-04 14:26 ` burnus at gcc dot gnu.org
  2012-04-04 15:20 ` izamyatin at gmail dot com
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-04-04 14:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-04-04 14:26:18 UTC ---
Reopen for reconsideration by the GCC's vectorization experts.


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

* [Bug tree-optimization/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (3 preceding siblings ...)
  2012-04-04 14:26 ` burnus at gcc dot gnu.org
@ 2012-04-04 15:20 ` izamyatin at gmail dot com
  2012-04-16  7:17 ` izamyatin at gmail dot com
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: izamyatin at gmail dot com @ 2012-04-04 15:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #5 from Igor Zamyatin <izamyatin at gmail dot com> 2012-04-04 15:20:41 UTC ---
Seems it doesn't like non-empty latch block in Fortran case


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

* [Bug tree-optimization/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (4 preceding siblings ...)
  2012-04-04 15:20 ` izamyatin at gmail dot com
@ 2012-04-16  7:17 ` izamyatin at gmail dot com
  2013-01-16  7:02 ` [Bug fortran/52865] " izamyatin at gmail dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: izamyatin at gmail dot com @ 2012-04-16  7:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #6 from Igor Zamyatin <izamyatin at gmail dot com> 2012-04-16 07:16:56 UTC ---
Any ideas what exactly does prevent the vectorization in the case of Fortran?


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (5 preceding siblings ...)
  2012-04-16  7:17 ` izamyatin at gmail dot com
@ 2013-01-16  7:02 ` izamyatin at gmail dot com
  2013-01-16 10:04 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: izamyatin at gmail dot com @ 2013-01-16  7:02 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Igor Zamyatin <izamyatin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus@net-b.de, izamyatin
                   |                            |at gmail dot com
          Component|tree-optimization           |fortran

--- Comment #7 from Igor Zamyatin <izamyatin at gmail dot com> 2013-01-16 07:02:03 UTC ---
Why for Fortran case loop is transformed in such form? It doesn't happen for C
so probably it's Fortran issue


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (6 preceding siblings ...)
  2013-01-16  7:02 ` [Bug fortran/52865] " izamyatin at gmail dot com
@ 2013-01-16 10:04 ` rguenth at gcc dot gnu.org
  2013-01-16 10:26 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-01-16 10:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-01-16
     Ever Confirmed|0                           |1

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> 2013-01-16 10:04:27 UTC ---
In another bug I stated that

    while (1)
      {
...
        if (countm1.0 == 0) goto L.2;
        countm1.0 = countm1.0 + 4294967295;
      }
    L.2:;

is bad for the vectorizer (the non-empty latch block).  You instead
want GFortran to emit

    while (1)
      {
...
        tem = countm1.0
        countm1.0 = countm1.0 + 4294967295;
        if (tem == 0) goto L.2;
      }
    L.2:;

where hopefully the addition does not overflow ...

That said, somewhat lessening the restriction on empty latch blocks is
certainly possible (IV increments should be fine), but it might be not
as trivial as it looks.


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (7 preceding siblings ...)
  2013-01-16 10:04 ` rguenth at gcc dot gnu.org
@ 2013-01-16 10:26 ` jakub at gcc dot gnu.org
  2013-01-16 10:47 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-16 10:26 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-16 10:25:48 UTC ---
countm1.0 type is unsigned, thus + 0xffffffff is effectively - 1.


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (8 preceding siblings ...)
  2013-01-16 10:26 ` jakub at gcc dot gnu.org
@ 2013-01-16 10:47 ` jakub at gcc dot gnu.org
  2013-01-16 11:32 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-16 10:47 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-16 10:47:18 UTC ---
BTW, does Fortran have well defined number of iterations if say a do loop goes
from (unknown to compiler):
  integer :: i, m, n
  m = huge(0) - 7
  n = huge(0) - 2
  do i = m, n, 4
   ...
  end do
?  If it must iterate exactly twice (for i = huge(0) - 7 and i = huge(0) - 3),
then it can't be expressed as a corresponding C loop (which would end up with
undefined behavior).  But using a temporary, increment and then test of the
temporary should be doable in the FE, the question is if it does cure this.


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (9 preceding siblings ...)
  2013-01-16 10:47 ` jakub at gcc dot gnu.org
@ 2013-01-16 11:32 ` burnus at gcc dot gnu.org
  2013-01-16 11:59 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-01-16 11:32 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #11 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-01-16 11:32:15 UTC ---
(In reply to comment #8)
> In another bug I stated that

See PR 53957


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (10 preceding siblings ...)
  2013-01-16 11:32 ` burnus at gcc dot gnu.org
@ 2013-01-16 11:59 ` jakub at gcc dot gnu.org
  2013-01-16 16:06 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-16 11:59 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-16 11:59:29 UTC ---
Created attachment 29178
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29178
gcc48-pr52865.patch

This untested patch makes the loop vectorizable.
Not sure if it is better this way, or with doing assignment of the condition
result into a bool and using it later (as done in the patch for the other PR).


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (11 preceding siblings ...)
  2013-01-16 11:59 ` jakub at gcc dot gnu.org
@ 2013-01-16 16:06 ` jakub at gcc dot gnu.org
  2013-01-16 22:27 ` steven at gcc dot gnu.org
  2013-03-28 13:24 ` rguenth at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-16 16:06 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-16 16:05:42 UTC ---
Author: jakub
Date: Wed Jan 16 16:05:27 2013
New Revision: 195241

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195241
Log:
    PR fortran/52865
    * trans-stmt.c (gfc_trans_do): Put countm1-- before conditional
    and use value of countm1 before the decrement in the condition.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-stmt.c


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (12 preceding siblings ...)
  2013-01-16 16:06 ` jakub at gcc dot gnu.org
@ 2013-01-16 22:27 ` steven at gcc dot gnu.org
  2013-03-28 13:24 ` rguenth at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: steven at gcc dot gnu.org @ 2013-01-16 22:27 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

--- Comment #14 from Steven Bosscher <steven at gcc dot gnu.org> 2013-01-16 22:27:31 UTC ---
(In reply to comment #13)
>     PR fortran/52865
>     * trans-stmt.c (gfc_trans_do): Put countm1-- before conditional
>     and use value of countm1 before the decrement in the condition.

Cool, this should help a few Polyhedron benchmarks! :-)


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

* [Bug fortran/52865] GCC can't vectorize fortran loop but able to vectorize similar c-loop
  2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
                   ` (13 preceding siblings ...)
  2013-01-16 22:27 ` steven at gcc dot gnu.org
@ 2013-03-28 13:24 ` rguenth at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-03-28 13:24 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52865

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #15 from Richard Biener <rguenth at gcc dot gnu.org> 2013-03-28 13:24:16 UTC ---
Vectorized now.


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

end of thread, other threads:[~2013-03-28 13:24 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-04 13:26 [Bug fortran/52865] New: GCC can't vectorize fortran loop but able to vectorize similar c-loop izamyatin at gmail dot com
2012-04-04 13:27 ` [Bug fortran/52865] " izamyatin at gmail dot com
2012-04-04 13:50 ` rguenth at gcc dot gnu.org
2012-04-04 14:00 ` [Bug tree-optimization/52865] " burnus at gcc dot gnu.org
2012-04-04 14:26 ` burnus at gcc dot gnu.org
2012-04-04 15:20 ` izamyatin at gmail dot com
2012-04-16  7:17 ` izamyatin at gmail dot com
2013-01-16  7:02 ` [Bug fortran/52865] " izamyatin at gmail dot com
2013-01-16 10:04 ` rguenth at gcc dot gnu.org
2013-01-16 10:26 ` jakub at gcc dot gnu.org
2013-01-16 10:47 ` jakub at gcc dot gnu.org
2013-01-16 11:32 ` burnus at gcc dot gnu.org
2013-01-16 11:59 ` jakub at gcc dot gnu.org
2013-01-16 16:06 ` jakub at gcc dot gnu.org
2013-01-16 22:27 ` steven at gcc dot gnu.org
2013-03-28 13:24 ` rguenth 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).