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

            Bug ID: 70102
           Summary: Tree re-association prevents SLP vectorization at
                    -Ofast.
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vekumar at gcc dot gnu.org
  Target Milestone: ---

The following test case failed to vectorize in gcc -Ofast. 

(---snip---)
      subroutine test (x,y,z)
      integer x,y,z
      real*8 a(5,x,y,z),b(5,x,y,z)
      real*8 c

      c = 0.0d0
      do k=1,z
         do j=1,y
           do i=1,x
              do l=1,5
                 c = c + a(l,i,j,k)*b(l,i,j,k)
              enddo
           enddo
         enddo
      enddo
      write(30,*)'c ==',c
      return
      end
(---snip---)

Vectorizer dump 
(---snip---)
test.f:9:0: note: original stmt _95 = _92 + _112;
test.f:9:0: note: Build SLP for _152 = _150 * _151;
test.f:9:0: note: Build SLP failed: different operation in stmt _152 = _150 *
_151;
test.f:9:0: note: original stmt _95 = _92 + _112;
test.f:9:0: note: Build SLP for _55 = _53 * _54;
test.f:9:0: note: Build SLP failed: different operation in stmt _55 = _53 *
_54;
test.f:9:0: note: original stmt _95 = _92 + _112;
test.f:1:0: note: vectorized 0 loops in function
(---snip---)

Re-association pass changes one of the tree expression and it prevents from SLP
block vectorization.

Before 
(---snip---)
 # VUSE <.MEM_7>
  _90 = *A.18_37[_89];
  # VUSE <.MEM_7>
  _91 = *A.20_40[_89];
  _92 = _90 * _91;
  # VUSE <.MEM_7>
  c.21_93 = cD.3439;
  c.22_94 = _92 + c.21_93;
  _109 = _87 + 2;
  # VUSE <.MEM_7>
  _110 = *A.18_37[_109];
  # VUSE <.MEM_7>
  _111 = *A.20_40[_109];
  _112 = _110 * _111;
  c.22_114 = c.22_94 + _112;
  _129 = _87 + 3;
(---snip---)


After tree-reassoc
(---snip---)
 # VUSE <.MEM_7>
  _90 = *A.18_37[_89];
  # VUSE <.MEM_7>
  _91 = *A.20_40[_89];
  _92 = _91 * _90;
  # VUSE <.MEM_7>
  c.21_93 = cD.3439;
  _109 = _87 + 2;
  # VUSE <.MEM_7>
  _110 = *A.18_37[_109];
  # VUSE <.MEM_7>
  _111 = *A.20_40[_109];
  _112 = _111 * _110;
  _31 = _112 + _92; <== new statement 
  _129 = _87 + 3;
(---snip---)

Reply via email to