[Bug tree-optimization/126470] New: [15/16/17 Regression] Wrong operand check on a != 0 ? a / b : 0 -> a / b iff b is nonzero fold

"ktkachov at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.