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

            Bug ID: 126470
           Summary: [15/16/17 Regression] Wrong operand check on a != 0 ?
                    a / b : 0  -> a / b iff b is nonzero fold
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

__attribute__((noipa)) int
f (int a, int *p)
{
  return a != 0 ? a / (*p | 1) : 0;
}

int
main (void)
{
  if (f (0, 0) != 0)
    __builtin_abort ();
  return 0;
}

The match.pd rule:
     (for op (trunc_div ceil_div floor_div round_div exact_div)
      (simplify
       (cond (ne @0 integer_zerop) (op@2 @3 @1) integer_zerop )
        (if (bitwise_equal_p (@0, @3)
             && tree_expr_nonzero_p (@1)
             / * Cannot make a expression with side effects
                unconditional. * /
             && expr_no_side_effects_p (@3))
         @2)))

The expr_no_side_effects_p is on the wrong operand

Reply via email to