https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98028

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, for
unsigned f1(unsigned i, unsigned j) {
  if (j != i) __builtin_unreachable();
  return i - j;
}
this is already optimized through:
  if (vr->varying_p ()
      && (code == PLUS_EXPR || code == MINUS_EXPR)
      && TREE_CODE (op1) == SSA_NAME
      && vr0.kind () == VR_RANGE
      && symbolic_range_based_on_p (&vr0, op1))
    {
      const bool minus_p = (code == MINUS_EXPR);
      value_range n_vr1;

      /* Try with VR0 and [-INF, OP1].  */
      if (is_gimple_min_invariant (minus_p ? vr0.max () : vr0.min ()))
        n_vr1.set (vrp_val_min (expr_type), op1);

      /* Try with VR0 and [OP1, +INF].  */
      else if (is_gimple_min_invariant (minus_p ? vr0.min () : vr0.max ()))
        n_vr1.set (op1, vrp_val_max (expr_type));

      /* Try with VR0 and [OP1, OP1].  */
      else
        n_vr1.set (op1, op1);

      range_fold_binary_expr (vr, code, expr_type, &vr0, &n_vr1);
    }
(and matching if below for the other range/operand pair) + the symbolic
handling
in range_fold_binary_symbolics_p -> extract_range_from_plus_minus_expr.
And that is also able to optimize
unsigned f1(unsigned i, unsigned j, unsigned *r) {
  if (j >= i) __builtin_unreachable();
  return __builtin_sub_overflow (i, j, r);
}
*r setting to 0.
But we don't have any such support for symbolics in
check_for_binary_op_overflow.

I guess it could be added even for GCC 11, the question is if it would be then
usable even for GCC 12 with smbolic ranges in ranger, or not.

Reply via email to