https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93041
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- So what is happening is (infinite) loops can be removed if they have no side effects. So we start with: <bb 2> : label1: if (p_3(D) != 0B) goto <bb 3>; [INV] else goto <bb 4>; [INV] <bb 3> : // predicted unlikely by goto predictor. goto <bb 2>; [INV] <bb 4> : _1 = *p_3(D); _2 = *_1; g3 = _2; return; And then we prop 0 into p_3 and then we remove the infinite loop. So we run into undefined behavior from dereferencing a null pointer. I think this code is undefined due to forward progress is required by the standards.