https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127661
Bug ID: 127661
Summary: Compile-time hog (in cprop.cc?)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: compile-time-hog
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ktkachov at gcc dot gnu.org
Target Milestone: ---
The following testcase takes minutes to compile on GCC while takes <1s on Clang
at -O2 -DN=2048
The extreme compile time seems to go back quite a bit, though I haven't
exhaustively checked GCC versions.
#ifndef N
#define N 2048
#endif
#ifndef VTYPE
#define VTYPE unsigned
#endif
#ifdef INLINE
struct Counter {
unsigned counts[N];
int crossIdx[N];
unsigned hits[1];
unsigned hitCount;
void hit(unsigned i) {
++counts[i];
const int cx = crossIdx[i];
if (cx >= 0 && hitCount < 1) hits[hitCount++] =
static_cast<unsigned>(cx);
}
};
#else
struct Counter {
void hit(unsigned i); // Defined elsewhere
};
#endif
// clang-format off
#define IF1(n) if (v == (n)) c->hit(n);
#define IF2(n) IF1(n) IF1((n) + 1)
#define IF4(n) IF2(n) IF2((n) + 2)
#define IF8(n) IF4(n) IF4((n) + 4)
#define IF16(n) IF8(n) IF8((n) + 8)
#define IF32(n) IF16(n) IF16((n) + 16)
#define IF64(n) IF32(n) IF32((n) + 32)
#define IF128(n) IF64(n) IF64((n) + 64)
#define IF256(n) IF128(n) IF128((n) + 128)
#define IF512(n) IF256(n) IF256((n) + 256)
#define IF1024(n) IF512(n) IF512((n) + 512)
#define IF2048(n) IF1024(n) IF1024((n) + 1024)
#define IF4096(n) IF2048(n) IF2048((n) + 2048)
#define IF8192(n) IF4096(n) IF4096((n) + 4096)
// clang-format on
#define CAT_(a, b) a##b
#define CAT(a, b) CAT_(a, b)
void sample(Counter* c, VTYPE v) { CAT(IF, N)(0u) }
A simple profiling run indicates that jump bypassing in cprop is the culprit.
Reporting on behalf of someone else.
Reported-by: Marco Bartoli <[email protected]>