[Bug middle-end/126418] New: PR113894 introduces new UB in optimized code

"kristerw 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=126418

            Bug ID: 126418
           Summary: PR113894 introduces new UB in optimized code
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristerw at gcc dot gnu.org
            Blocks: 118443
  Target Milestone: ---

The function below does not invoke undefined behavior when called as:
  f_cmp_gt_commuted(0x80000000, 0);

int f_cmp_gt_commuted(int x, int y)
{
  int cmp = x > y;
  return cmp + (-cmp ^ x);
}

But compiling this for x86_64 with -O1 makes forwprop1 transform it into the
GIMPLE below, where the computation of _9 invokes undefined behavior:

int f_cmp_gt_commuted (int x, int y)
{
  int cmp;
  bool _1;
  int _7;
  int _9;

  <bb 2> :
  _1 = x_4(D) > y_5(D);
  _9 = -x_4(D);
  _7 = _1 ? _9 : x_4(D);
  return _7;
}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing
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.