int bar(int i) { return -i-1+i+1; } optimizes to
;; Function bar (bar) Analyzing Edge Insertions. bar (i) { <bb 2>: return i + 1 + ~i; } (instead of return 0; which we catch at rtl level later) Either i+1 needs to be folded to -~i, we need to re-associate earlier or something needs to do tree-combining and recognize that ~i and -(i+1) is the same. This happens in tramp3d as loop exit condition and shows up as if (d.22083 != (int) ((unsigned int) d + 1 + (unsigned int) D.902833 + (unsigned int) ~d)) goto <L3>; else goto <L6>; instead of just if (d.22083 != D.902833) goto <L3>; else goto <L6>; [I think most of these "interesting" foldings should be deferred] -- Summary: fold folds -i-1+i+1 to ~i+i+1 Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: missed-optimization, TREE Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rguenth at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30322