https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81549
Bug ID: 81549 Summary: PHI node should be eliminated if loop iterates enough times. Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: amker at gcc dot gnu.org Target Milestone: --- Given below test: int a[10000], b[10000], c[10000]; int f(void) { int i, n = 100; int t0 = a[0]; int t1 = a[1]; for (i = 0; i < n; i++) { a[i] = 1; int t2 = 2; t0 = t1; t1 = t2; } a[n] = t0; a[n+1] = t1; return 0; } Compile it at Ofast by default, the optimized dump is as: <bb 2> [1.00%] [count: INV]: t1_8 = a[1]; ivtmp.9_17 = (unsigned long) &a; _16 = ivtmp.9_17 + 400; <bb 3> [99.00%] [count: INV]: # t1_20 = PHI <2(3), t1_8(2)> # ivtmp.9_2 = PHI <ivtmp.9_1(3), ivtmp.9_17(2)> _15 = (void *) ivtmp.9_2; MEM[base: _15, offset: 0B] = 1; ivtmp.9_1 = ivtmp.9_2 + 4; if (ivtmp.9_1 != _16) goto <bb 3>; [98.99%] [count: INV] else goto <bb 4>; [1.01%] [count: INV] <bb 4> [1.00%] [count: INV]: a[100] = t1_20; a[101] = 2; return 0; We now eliminate one phi and leave another behind. It is vrp1/dce2 when the phi is eliminated.