https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82062
--- Comment #6 from Eric Botcazou <ebotcazou at gcc dot gnu.org> --- > Looks like you have sth in mind, care to post a candidate patch? The candidate patch would just be Marek's initial fix in comment #8: --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3401,14 +3401,14 @@ operand_equal_for_comparison_p (tree arg0, tree arg1, tree other) primarg1 = get_narrower (arg1, &unsignedp1); primother = get_narrower (other, &unsignedpo); + tree type = TREE_TYPE (arg0); correct_width = TYPE_PRECISION (TREE_TYPE (arg1)); if (unsignedp1 == unsignedpo + && TYPE_PRECISION (TREE_TYPE (primarg1)) == TYPE_PRECISION (type) && TYPE_PRECISION (TREE_TYPE (primarg1)) < correct_width && TYPE_PRECISION (TREE_TYPE (primother)) < correct_width) { - tree type = TREE_TYPE (arg0); - /* Make sure shorter operand is extended the right way to match the longer operand. */ primarg1 = fold_convert (signed_or_unsigned_type_for