Consider: struct s { int *n; };
int foo (unsigned int i, struct s *array) { int *p = array[i].n; if (p) { int *q = array[i].n; if (p != q) return 1; } return 0; } Note that the second load is unnecessary, but FRE does not remove it. Here is the dump before FRE. foo (i, array) { int * q; int * p; int D.1142; struct s * D.1141; struct s * D.1140; unsigned int D.1139; <bb 0>: D.1139_3 = i_2 * 4; D.1140_4 = (struct s *) D.1139_3; D.1141_6 = D.1140_4 + array_5; # VUSE <TMT.0_15>; p_7 = D.1141_6->n; if (p_7 != 0B) goto <L0>; else goto <L2>; <L0>:; D.1139_10 = i_2 * 4; D.1140_11 = (struct s *) D.1139_10; D.1141_12 = array_5 + D.1140_11; # VUSE <TMT.0_15>; q_13 = D.1141_12->n; if (p_7 != q_13) goto <L1>; else goto <L2>; <L1>:; D.1142_14 = 1; goto <bb 4> (<L4>); <L2>:; D.1142_9 = 0; # D.1142_1 = PHI <1(2), 0(3)>; <L4>:; return D.1142_1; } After FRE: foo (i, array) { int * q; int * p; int D.1142; struct s * D.1141; struct s * D.1140; unsigned int D.1139; <bb 0>: D.1139_3 = i_2 * 4; D.1140_4 = (struct s *) D.1139_3; D.1141_6 = D.1140_4 + array_5; # VUSE <TMT.0_15>; p_7 = D.1141_6->n; if (p_7 != 0B) goto <L0>; else goto <L2>; <L0>:; D.1139_10 = D.1139_3; D.1140_11 = D.1140_4; D.1141_12 = D.1141_6; # VUSE <TMT.0_15>; q_13 = D.1141_12->n; if (p_7 != q_13) goto <L1>; else goto <L2>; <L1>:; D.1142_14 = 1; goto <bb 4> (<L4>); <L2>:; D.1142_9 = 0; # D.1142_1 = PHI <1(2), 0(3)>; <L4>:; return D.1142_1; } -- 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: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20725