Bug 35343 - Sum-reduction loop not recognized (enable -fvariable-expansion-in-unroller by default)
Summary: Sum-reduction loop not recognized (enable -fvariable-expansion-in-unroller by...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2008-02-24 04:28 UTC by davidxl
Modified: 2008-12-29 06:30 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-12-29 06:30:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description davidxl 2008-02-24 04:28:01 UTC
It is beneficial to unroll reduction loop (and split the reduction target) to reduce dependence height due to recurrence, but GCC does not perform such optimization (-O3 -fno-tree-vectorize)


int a[1000];
int b[1000];
int foo(int n)
{

   int s = 0;
   int i = 0;
   for (i = 0; i < 1000 ; i++)
   {
       s += a[i] + b[2*i];
   }
   return s;
}
Comment 1 dorit 2008-02-25 10:21:49 UTC
(In reply to comment #0)
> It is beneficial to unroll reduction loop (and split the reduction target) to
> reduce dependence height due to recurrence, but GCC does not perform such
> optimization (-O3 -fno-tree-vectorize)

it does, if you use -fvariable-expansion-in-unroller -funroll-loops
(this splits the reduction target into 2 accumulators. For more agressive spiltting you can use --param max-variable-expansions-in-unrolle=[n])
Comment 2 davidxl 2008-02-25 21:36:30 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > It is beneficial to unroll reduction loop (and split the reduction target) to
> > reduce dependence height due to recurrence, but GCC does not perform such
> > optimization (-O3 -fno-tree-vectorize)
> 
> it does, if you use -fvariable-expansion-in-unroller -funroll-loops
> (this splits the reduction target into 2 accumulators. For more agressive
> spiltting you can use --param max-variable-expansions-in-unrolle=[n])
> 

Thanks, it is good to know the option. It would be good to tune the default behavior of the optimizer so that better out of box performance can be achieved. 
Comment 3 Andrew Pinski 2008-12-29 06:30:36 UTC
Confirmed.