Consider:

int
foo (int *array)
{
  if (array[1] != 0)
    return array[1];
  return 0;
}

Here is the result after the first DCE, which is immediately after FRE.



foo (array)
{
  int D.1134;
  int D.1133;
  int * D.1132;

<bb 0>:
  D.1132_3 = array_2 + 4B;
  D.1133_4 = *D.1132_3;
  if (D.1133_4 != 0) goto <L0>; else goto <L2>;

<L0>:;
  D.1132_7 = D.1132_3;
  D.1134_8 = *D.1132_7;

  # D.1134_1 = PHI <D.1134_8(1), 0(0)>;
<L2>:;
  return D.1134_1;

}

Note that the second load still stays there.

If I run copy-prop and FRE one more time immediately after running them
for the first time, then the second run of FRE can remove the redundant load.
By running the copy prop one more time, the second load becomes:

  D.1134_8 = *D.1132_3;

Then then I guess it's easy for FRE to eliminate this load because
RHS looks exactly like the first load.

-- 
           Summary: [tcb] FRE does not remove a fully redundant load.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: dnovillo at redhat dot com,gcc-bugs at gcc dot gnu dot
                    org


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

Reply via email to