Consider: int foo (int a) { int b = a != 0; if (b) if (a != 0) return 1; return 0; }
With "-O2 -ftree-no-dominator-opts", VRP generates: foo (a) { int b; int D.1153; <bb 0>: b_3 = a_2 != 0; if (b_3 != 0) goto <L0>; else goto <L2>; <L0>:; if (a_2 != 0) goto <L1>; else goto <L2>; <L1>:; D.1153_6 = 1; goto <bb 4> (<L4>); <L2>:; D.1153_5 = 0; # D.1153_1 = PHI <D.1153_6(2), D.1153_5(3)>; <L4>:; return D.1153_1; } Note that the second "if" statement is always true, but VRP does not notice that. Forward-propagating "a_2 != 0" into the first "if" statement will do the desired optimization. -- Summary: VRP is weak when the tested variable in a COND_EXPR is used in the COND_EXPR. Product: gcc Version: unknown Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P2 Component: tree-optimization AssignedTo: kazu at cs dot umass dot edu 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=21001