Bug 35345

Summary: Scalar replacement to handle output dependence
Product: gcc Reporter: davidxl <xinliangli>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: gcc-bugs, rakdver
Priority: P3 Keywords: missed-optimization
Version: 4.3.0   
Target Milestone: 10.0   
Host: Target:
Build: Known to work: 10.0
Known to fail: 7.4.0 Last reconfirmed: 2021-06-08 00:00:00

Description davidxl 2008-02-24 04:40:22 UTC
// David Li
Gcc's scalar replacement and predictive commoning implementation is very good. There are some missing cases. Handling output dependence is one of them.

Handling of output dependence. In this case, the store at (1) is dead except for the last iteration -- it should be sinked out of the loop. (-O3 -fno-tree-vectorize)

int a[1000];
int b[1000];

void foo(int n)
{
   int i = 1;
   for(; i < n; i++)
   {
        a[i+1] =i;     // (1) 
        a[i] = i+1;
   }
}
Comment 1 Andrew Pinski 2008-04-07 01:38:45 UTC
Confirmed.
Comment 2 Andrew Pinski 2021-06-08 09:30:38 UTC
Fixed in GCC 10 and above.