https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61734
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Sure, I wouldn't change fold_cond_expr_with_comparison itself. Instead, next to the two spots that call fold_cond_expr_with_comparison add another two, which would if arg1 or op2 is a MINUS_EXPR where the first MINUS_EXPR operand is equal to one comparison operand and the other to the other one, basically undo your transformation for the purpose of the fold_cond_expr_with_comparison call; if that returns non-NULL, we'd fold to that, essentially undoing your transformation, but otherwise we wouldn't undo anything. Perhaps in addition to MINUS_EXPR we should handle PLUS_EXPR with INTEGER_CST second operand, so A >= 5 ? (A + (-5)) : -(A + (-5)) and similar cases.