https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121921
Bug ID: 121921 Summary: `b - (b - e)` for pointers is not optimized to just e Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` char *a(char *b, char *e) { return e - (e - b); } ``` This gets optimized to `return b` on the RTL level but I suspect it should be optimized to b on gimple too. Noticed this in PR 117924. There we fully have: ``` _201 = _36 + _35; ... _9 = _201 - _36; _10 = (long unsigned int) _9; _11 = -_10; _12 = _201 + _11; ``` (which does get optimized but only during forwprop4). But I suspect if we optimize this earlier we could do the dse of the memset earlier there and then dce of the `operator new/delete` earlier too.