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

            Bug ID: 98028
           Summary: __builtin_sub_overflow_p not folded to const when some
                    constraints are known
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

According to godbolt, f1 used to be optimised with gcc 7.

The same problem can be seen with signed types (and maybe more conditions?).
All the following functions should be only one instruction plus ret with O2

-----------------
unsigned f1(unsigned i, unsigned j) {
  if (j != i) __builtin_unreachable();
  return __builtin_sub_overflow_p(i, j, (unsigned)0);
}

unsigned f2(unsigned i, unsigned j) {
  if (j > i) __builtin_unreachable();
  return __builtin_sub_overflow_p(i, j, (unsigned)0);
}

unsigned f3(unsigned i, unsigned j) {
  if (j >= i) __builtin_unreachable();
  return __builtin_sub_overflow_p(i, j, (unsigned)0);
}

unsigned f4(unsigned i, unsigned j) {
  if (j < i) __builtin_unreachable();
  return __builtin_sub_overflow_p(i, j, (unsigned)0);
}
-----------------
  • [Bug tree-optimization/98028... denis.campredon at gmail dot com via Gcc-bugs

Reply via email to