Bug 26359

Summary: [4.2 Regression] Over optimization of loop when using -ftree-vectorize
Product: gcc Reporter: Anton Blanchard <anton>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: dnovillo, dorit, gcc-bugs, victork
Priority: P3 Keywords: alias, wrong-code
Version: 4.2.0   
Target Milestone: 4.2.0   
Host: Target:
Build: Known to work: 4.1.0
Known to fail: 4.2.0 4.1.0 Last reconfirmed: 2006-02-19 02:26:33
Bug Depends on: 36244    
Bug Blocks:    

Description Anton Blanchard 2006-02-19 02:24:01 UTC
Using a gcc build from today I tried one of the autovectorization test cases and found it over optimized:

$ ~/toolchain/install/bin/gcc  -v
Using built-in specs.
Target: powerpc-linux
Configured with: /home/anton/toolchain/gcc/gcc/configure --build=powerpc-linux --host=powerpc-linux --target=powerpc-linux --enable-targets=powerpc64-linux --enable-languages=c,c++,fortran --prefix=/home/anton/toolchain/install
Thread model: posix
gcc version 4.2.0 20060215 (experimental)

$ cat example1.c
int a[256], b[256], c[256];
foo () {
  int i;

  for (i=0; i<256; i++){
    a[i] = b[i] + c[i];
  }
}

$ ~/toolchain/install/bin/gcc -c -O1 -ftree-vectorize -ftree-vectorizer-verbose=5 -maltivec -o example1_vect.o example1.c

example1.c:5: note: LOOP VECTORIZED.
example1.c:5: note: vectorized 1 loops in function.

$ objdump -d example1_vect.o

example1_vect.o:     file format elf32-powerpc

Disassembly of section .text:

00000000 <foo>:
   0:   94 21 ff f0     stwu    r1,-16(r1)
   4:   38 00 00 40     li      r0,64
   8:   7c 09 03 a6     mtctr   r0
   c:   42 00 00 00     bdnz-   c <foo+0xc>
  10:   38 21 00 10     addi    r1,r1,16
  14:   4e 80 00 20     blr
Comment 1 Andrew Pinski 2006-02-19 02:26:33 UTC
Confirmed, also fails on x86_64.

This is a regression from 4.1.0.  It also looks like an aliasing issue too as DCE is removing the statements.
Comment 2 Dorit Naishlos 2006-02-19 15:34:05 UTC
The problem is that during dce the call to is_hidden_global_store returns false cause the tag is not marked as global/static.

This seems to fix it:

Index: tree-ssa-alias.c
===================================================================
*** tree-ssa-alias.c    (revision 110911)
--- tree-ssa-alias.c    (working copy)
*************** new_type_alias (tree ptr, tree var)
*** 2638,2643 ****
--- 2638,2651 ----
            add_may_alias (tag, al);
        }
      }
+ 
+   /* CHECKME:
+   DECL_CONTEXT (tag) = DECL_CONTEXT (var);
+   TREE_PUBLIC  (tag) = TREE_PUBLIC (var);
+   TREE_READONLY (tag) = TREE_READONLY (var);
+   */
+   MTAG_GLOBAL (tag) = DECL_EXTERNAL (var);
+   TREE_STATIC (tag) = TREE_STATIC (var);
  }

but I don't know if it's the right thing to do in the general case.
Comment 3 Dorit Naishlos 2006-02-21 22:01:30 UTC
patch:
http://gcc.gnu.org/ml/gcc-patches/2006-02/msg01710.html
Comment 4 patchapp@dberlin.org 2006-02-22 01:35:25 UTC
Subject: Bug number PR tree-optimization/26359

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-02/msg01710.html
Comment 5 dorit 2006-02-26 09:27:38 UTC
Subject: Bug 26359

Author: dorit
Date: Sun Feb 26 09:27:35 2006
New Revision: 111451

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111451
Log:
        PR tree-optimization/26359
        * tree-ssa-alias.c (new_type_alias): Set fields for new tag.


Added:
    trunk/gcc/testsuite/gcc.dg/vect/dump-tree-dceloop-pr26359.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/vect/vect.exp
    trunk/gcc/tree-ssa-alias.c

Comment 6 Andrew Pinski 2006-02-26 14:44:43 UTC
Fixed.