https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81814
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Ugh, I believe fold_cond_expr_with_comparison does Very Bad stuff: it sees A == 0 ? A : 0 and thinks that it can be optimized to 0, btu it can't, in this case we have (signed char) xxx == 0 ? (unsigned long long) xxx : 0 (signed char) xxx is indeed 0 but (unsigned long long) xxx is not.