https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108481
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> i = i - 6822162149299574294;
>
> Is not being invoked on the executable code.
>
> If we look at look at the original code:
>
>
> if ((i * (unsigned long)7 <= 1) << j)
> ;
> else {
> i = i - 6822162149299574294;
> if (j) {
> if (*g)
> break;
> continue;
> }
> return 8;
> }
> ...
> return h;
>
> The only path where the undefined behavior even matters is inside the path
> that had continue in it. Which is where the subtraction is pushed to now.
>
> I don't know if we should declear this as a valid thing to do or not.
This is what the IR looks in the end:
_27 = _17 << _20;
if (_27 != 0)
goto <bb 12>; [50.00%]
else
goto <bb 9>; [50.00%]
<bb 9> [local count: 1560331071]:
if (_20 != 0)
goto <bb 10>; [94.50%]
else
goto <bb 13>; [5.50%]
<bb 10> [local count: 1474512859]:
_30 = a;
if (_30 != 0)
goto <bb 13>; [67.00%]
else
goto <bb 11>; [33.00%]
<bb 11> [local count: 486589241]:
i_28 = .UBSAN_CHECK_SUB (i_13, 6822162149299574294);
<bb 12> [local count: 2046920311]:
# i_34 = PHI <i_13(8), i_28(11)>
(Loop back)
...
<bb 13> [local count: 1073741830]:
return 0;
As you can see the only path where the ubsan_check_sub is executed is right
before the continue which is seems like a very valid thing to do.