https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102569
Bug ID: 102569 Summary: Missed redudant add with add_overflow on the tree level Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization, TREE Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: bool f1(unsigned x, unsigned y, unsigned *res) { bool t = __builtin_add_overflow(x, y, res); *res -= (x+y); return t; } ----- CUT ---- We currently get: _7 = .ADD_OVERFLOW (x_5(D), y_6(D)); _1 = REALPART_EXPR <_7>; _2 = IMAGPART_EXPR <_7>; t_10 = (bool) _2; _3 = x_5(D) + y_6(D); _4 = _1 - _3; But _3 and _1 are the same _4 should be optimized to 0 as it is on the RTL level. The way I see this being done is during the late fre add x+y in the table for REALPART_EXPR<_7> and it will be done correctly.