https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127159
Bug ID: 127159
Summary: [17 Regression] A TSVC testcase slower since
r17-3575-g0b23ae2669d274 on AMD Zen4/5
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: pheeck at gcc dot gnu.org
CC: vekumar at gcc dot gnu.org
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
As you can see here
https://lnt.opensuse.org/db_default/v4/CPP/graph?plot.0=553.869.0
https://lnt.opensuse.org/db_default/v4/CPP/graph?plot.0=987.869.0
the s258 testcase from the TSVC benchmarking suite slowed down recently. Here
is the testcase modified so that it can be run independently and so that it
runs longer:
--- testcase.c ---
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
#define ARRAY_ALIGNMENT 64
#define LEN_2D 32000
#define iterations 100000
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float a[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float b[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float c[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float d[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float e[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float aa[1024][LEN_2D];
int dummy(float[LEN_2D], float[LEN_2D], float[LEN_2D], float[LEN_2D],
float[LEN_2D], float[1024][LEN_2D], float[1024][LEN_2D], float[1024][LEN_2D],
float);
void initialise_a();
__attribute__((aligned(ARRAY_ALIGNMENT))) float a[LEN_2D];
__attribute__((aligned(ARRAY_ALIGNMENT))) float b[LEN_2D];
__attribute__((aligned(ARRAY_ALIGNMENT))) float c[LEN_2D];
__attribute__((aligned(ARRAY_ALIGNMENT))) float d[LEN_2D];
__attribute__((aligned(ARRAY_ALIGNMENT))) float e[LEN_2D];
__attribute__((aligned(ARRAY_ALIGNMENT))) float aa[1024][LEN_2D];
int main()
{
// scalar and array expansion
// wrap-around scalar under an if
initialise_a();
for (int nl = 0; nl < iterations; nl++) {
float s;
s = 0.;
for (int i = 0; i < LEN_2D; ++i) {
if (a[i] > 0.) {
s = d[i] * d[i];
}
b[i] = s * c[i] + d[i];
e[i] = (s + (float)1.) * aa[0][i];
}
dummy(a, b, c, d, e, aa, (float(*)[LEN_2D])0, (float(*)[LEN_2D])0, 0.);
}
return 0;
}
--- ---
--- testcase2.c ---
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#define ARRAY_ALIGNMENT 64
#define LEN_2D 32000
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float a[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float b[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float c[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float d[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float e[LEN_2D];
extern __attribute__((aligned(ARRAY_ALIGNMENT))) float aa[1024][LEN_2D];
void initialise_a()
{
for (int i = 0; i < LEN_2D; i++) {
a[i] = 1.;
b[i] = 1.;
c[i] = 1.;
d[i] = 1.;
e[i] = 1.;
}
for (int i = 0; i < 1024; i++) {
for (int j = 0; j < LEN_2D; j++) {
aa[i][j] = 1.;
}
}
}
int dummy(float a[LEN_2D], float b[LEN_2D], float c[LEN_2D], float d[LEN_2D],
float e[LEN_2D], float aa[1024][LEN_2D], float bb[1024][LEN_2D], float
cc[1024][LEN_2D], float x)
{
return 0;
}
--- ---
Compile and run it with -Ofast -march=native on a Zen4 or a Zen5 machine. On
our Zen4 machine, this is the result
[fkastl@ryzen4 foo]$ binaries/0b23ae2669d/bin/gcc -Ofast -march=native -lm
testcase.c testcase2.c -o tsvc && time ./tsvc
real 0m1.785s
user 0m1.762s
sys 0m0.023s
[fkastl@ryzen4 foo]$ binaries/14911d6c952/bin/gcc -Ofast -march=native -lm
testcase.c testcase2.c -o tsvc && time ./tsvc
real 0m1.582s
user 0m1.566s
sys 0m0.016s
[fkastl@ryzen4 foo]$
I've bisected the slowdown to r17-3575-g0b23ae2669d274
commit 0b23ae2669d27460d87cdd36473b11d14b8bb8a2
Author: vekumar <[email protected]>
AuthorDate: Tue Aug 18 23:20:06 2026 +0530
Commit: vekumar <[email protected]>
CommitDate: Mon Aug 24 12:02:35 2026 +0530
x86: Increase znver4/5 tune branch misprediction cost
Increase the branch misprediction scale for znver4/5 tuning from
COSTS_N_INSNS (2) to COSTS_N_INSNS (2) + 3.
This improves 544.nab_r by 12% (-O3 -march=native -flto) on Znver5
and 9% on Znver4 with single-copy.
gcc/ChangeLog:
* config/i386/x86-tune-costs.h (znver4_cost): Increase branch
mispredict scale from COSTS_N_INSNS (2) to COSTS_N_INSNS (2) + 3.
(znver5_cost): Likewise.