https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64084
Bug ID: 64084 Summary: [5 Regression] match-and-simplify prefers complex matches Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org For int foo (int x) { int y = 0; int z = x + 1; return z + y; } the first CCP pass ends up producing z_3 = x_2(D) + 1; _4 = x_2(D) + 1; return _4; because (A + CST) + CST' -> A + (CST + CST') matches before A + 0 -> A. This is because we build the decision tree depth-first (the idea was to delay possibly expensive predicate evaluations as much as possible). I suppose if we'd build the decision tree breath first we would match the "correct" one first. For the testcase FRE of course fixes things up for us. Similarly we could drop SSA edge following from the folding done in substitute_and_fold. But forwprop would have the same issue (in fact it _did_ have the same issue in 4.9 if you disable CCP - or rather not, because then nothing propagates the zero).