https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126195
Bug ID: 126195
Summary: [15.2/15.3 Regression] 737.gmsh_r validation error
with "-O3 -march=native"
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: haochen.jiang at intel dot com
Target Milestone: ---
On GCC15.2/3 737.gmsh_r will meet RUNFAIL with -O3 -march=native on multiple
Intel platforms, including Ice Lake, Granite Rapids, Sierra Forest, Clearwater
Forest, etc.
The first FAIL commit is r15-9782, which is cherry-picked from r16-496. On
trunk, this commit also got a RUNFAIL on 737.gmsh_r.
On trunk, the RUNFAIL was fixed by r16-1265. However, the commit touched
totally different code. Thus, I believe it just hide the issue and should not
be backported to GCC 15 to solve the issue.
It seems to me that it is FMA vectorization to cause the floating point
calculation issue, where it switches the calculation order for the cases like
this:
void __attribute__((noinline))
dots(double v0,double v1,double v2,
double x0,double x1,double x2,
double y0,double y1,double y2,
double* __restrict res)
{
res[0] = v0*x0 + v1*x1 + v2*x2;
res[1] = v0*y0 + v1*y1 + v2*y2;
}
(https://godbolt.org/z/oTKbaW69n)
For vector and scalar, one calculate v1*x1 first, the other calculate v0*x0
first. This will not violate no-associative-math, but will affect final result
due to different rounding order. Then eventually leading to a totally different
code path in mesh.
It does not meet RUNFAIL on znver machines. It seems to me that znver will keep
FMA scalar in some cases when icelake-server vectorize, due to the cost for
scalar FP add/mul, znver using 3, icelake_cost using 4. Scalar version is ok
for 737.gmsh_r.
The option is widely used in Ubuntu, so we might need some solution for that,
either a stronger restriction for 737.gmsh_r on optimize options (maybe
-ffp-contract=off since I tested no perf impact), or maybe some optimization
restriction with FMA where might cause floating point issue.