[Bug tree-optimization/95396] [8/9/10/11 Regression] GCC produces incorrect code with -O3 for loops since r8-6511-g3ae129323d150621
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jul 7 08:20:30 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95396
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
One odd thing is that for unsigned char _3 we get via
wide_int var_min, var_max;
value_range_kind vr_type = get_range_info (tmp_var, &var_min,
&var_max);
[241, 255]
the add of 15 then overflows for both min and max and thus we happily accept
the result but compute the difference signed (in widest_int):
/* Calculate (ssizetype) OP0 - (ssizetype) TMP_VAR. */
widest_int diff = (widest_int::from (op0_min, sgn)
- widest_int::from (var_min, sgn));
var0 = tmp_var;
*off = wide_int_to_tree (ssizetype, diff);
which then results in 0-241 == -241.
To me it looks like we should instead do
/* Calculate (ssizetype) (OP0 - TMP_VAR). */
widest_int diff = widest_int::from (op0_min - var_min, sgn);
which fixes this particular testcase.
More information about the Gcc-bugs
mailing list