The following code:

long long foo (long long); 

void
FIR(short In[],short Out[],int nsamples)
{
  long long * vIn = (long long*)In;
  long long * vOut = (long long*)Out;
  int i;
  long long sum0, sum1;

  for (i = 0; i < nsamples; i++) {

          sum0 = vIn[i]; 

    vOut[i+1] = foo( 
        ({union {long long d; int w[2];} tmp_union; 

        tmp_union.w[0] = ( ({ union {long long d; int w[2];} tmp_union; 
        tmp_union.d = (sum0); 
        tmp_union.w[0]; })); 

        tmp_union.w[1] = ( ({ union {long long d; int w[2];} tmp_union; 
        tmp_union.d = (sum1); 
        tmp_union.w[0]; })); 
        tmp_union.d; })
        ); 
  }
}

Compiled with:
>gcc  -O2 -S ttt.c

>gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-threads=posix
--prefix=/prj/x86_gcc_4.4/bin --enable-languages=c,c++ --disable-checking
Thread model: posix
gcc version 4.4.0 (GCC)

produces redundant (dead) stores to local stack location. The problem goes away
with tree loop invariant code motion disabled (-fno-tree-loop-im flag). 

It also works fine with gcc 4.3.2 -O2 

I could track it down to the point of TREE_ADDRESSABLE flag (improperly) set to
tmp_union declaration tree during tree-loop-im:

#0  build_fold_addr_expr_with_type_1 (t=0x2b88d7d5b780, ptrtype=0x2b88d7d62e40,
in_fold=0 '\0') at fold-const.c:7945
#1  0x0000000000a1201d in get_inner_reference_aff (ref=<value optimized out>,
addr=0x7fffd31e6330, size=0x7fffd31e6430) at tree-affine.c:844
#2  0x00000000007eab9d in ref_indep_loop_p (loop=0x2b88d7c0cea0, ref=0xdea300)
at tree-ssa-loop-im.c:1643
#3  0x00000000007eb7f7 in determine_max_movement (stmt=0x2b88d7c01850,
must_preserve_exec=<value optimized out>) at tree-ssa-loop-im.c:589
#4  0x00000000007efce0 in determine_invariantness_stmt (dw_data=<value
optimized out>, bb=<value optimized out>) at tree-ssa-loop-im.c:971
#5  0x00000000009c8546 in walk_dominator_tree (walk_data=0x7fffd31e6770,
bb=0x2b88d7d5e720) at domwalk.c:196
#6  0x00000000007ea458 in determine_invariantness () at tree-ssa-loop-im.c:1005
#7  0x00000000007ef0c0 in tree_ssa_lim () at tree-ssa-loop-im.c:2299
#8  0x000000000080d4e5 in tree_ssa_loop_im () at tree-ssa-loop.c:110
#9  0x0000000000687a79 in execute_one_pass (pass=0xcae480) at passes.c:1277
#10 0x0000000000687c7c in execute_pass_list (pass=0xcae480) at passes.c:1326
#11 0x0000000000687c95 in execute_pass_list (pass=0xcae540) at passes.c:1327
#12 0x0000000000687c95 in execute_pass_list (pass=0xcad5e0) at passes.c:1327
#13 0x000000000077acfd in tree_rest_of_compilation (fndecl=0x2b88d7d41a00) at
tree-optimize.c:420
#14 0x00000000008ffb15 in cgraph_expand_function (node=0x2b88d7d41b00) at
cgraphunit.c:1047
#15 0x000000000090182a in cgraph_optimize () at cgraphunit.c:1106
#16 0x0000000000416a1f in c_write_global_declarations () at c-decl.c:8102
#17 0x0000000000723b46 in toplev_main (argc=<value optimized out>, argv=0x0) at
toplev.c:981

When present, it causes severe performance degradation.


-- 
           Summary: Redundant (dead) virtual-stack-vars stores related to
                    tree-loop-im
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sergei_lus at yahoo dot com


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

Reply via email to