https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80738
Bug ID: 80738 Summary: dead first stmt in a=0;a=b;b=0 whatever the aliasing Product: gcc Version: 8.0 Status: UNCONFIRMED Keywords: alias, missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- In C++, with move/swap, we regularly see the following appear void f(int&a,int&b){ a=0; a=b; b=0; } If a and b do not alias, the first statement is clearly killed by the second. If a and b are the same, the last statement kills all the rest. So in all cases, the first statement is dead. (we could imagine that removing it means that in some cases, we will copy uninitialized memory to itself, but that doesn't seem so bad) This is yet another case where the same optimization is valid whether 2 pointers alias or not, like PR 66261 or PR 80617, but the others were more about propagation and this one is about dead code... It seems hard to detect (involves 4 gimple statements, and plenty of intermediate statements could interfere), the gain may not be worth it. If we split the paths just right: if(&a!=&b){a=0;a=b;}else{a=0;a=b;}b=0; becomes if(&a!=&b)a=b; b=0; and the if could be done unconditionally... Seems unlikely.