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

            Bug ID: 117278
           Summary: [12/13/14/15 regression] Code at -Os is larger on
                    trunk than GCC 11.4.0
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dccitaliano at gmail dot com
  Target Milestone: ---

Looks like this regressed in GCC 12 and has never recovered since.

Testcase (https://godbolt.org/z/T1vvzWjvK)

int patatino(int* a) {
  if (*a > 5 && *a % 2 == 0) {
    if ((*a / 2) % 3 != 0) {
      *a = *a / 2;
      for (int i = 0; i < *a; i++) {
        if (i % 2 == 0 && (*a - i) % 3 != 0 && (i + (*a - i)) % 11 != 0) {
          for (int j = i; j < *a; j += 2) {
            *a += j % 5;
            if (j > *a / 3 && (*a + j) % 7 == 0 && (j * 2 + *a) % 13 == 0) {
              *a -= j / 2;
            }
          }
        }
      }
    } else {
      *a = 0;
    }
  } else {
    *a = *a + 1;
  }
  return 0;
}


Bisects to:

dc1969dab392661cdac1170bbb8c9f83f388580d is the first bad commit
commit dc1969dab392661cdac1170bbb8c9f83f388580d
Author: Xionghu Luo <luo...@linux.ibm.com>
Date:   Wed Dec 29 20:02:12 2021 -0600

    loop-invariant: Don't move cold bb instructions to preheader in RTL

    gcc/ChangeLog:

    2021-12-30  Xionghu Luo  <luo...@linux.ibm.com>

            * loop-invariant.c (find_invariants_bb): Check profile count
            before motion.
            (find_invariants_body): Add argument.

    gcc/testsuite/ChangeLog:

    2021-12-30  Xionghu Luo  <luo...@linux.ibm.com>

            * gcc.dg/loop-invariant-2.c: New.

 gcc/loop-invariant.c                    | 17 ++++++++++++++---
 gcc/testsuite/gcc.dg/loop-invariant-2.c | 20 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/loop-invariant-2.c
bisect found first bad commit

Reply via email to