[Bug fortran/110888] Missing optimization for trivial MATMUL cases, requires -fno-signed-zeros
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110888 --- Comment #5 from Rimvydas (RJ) --- It is more like this problem: $ cat foo.c void foo_(double *x, double *y, double *z) { int i; __builtin_memset(z, 0, 8); /* z[0] = 0.0; */ for (i=0; i<1 ; i++) z[0] += x[0] * y[0]; } $ gcc -O2 -Wall -Wextra -c foo.c -S -fdump-tree-optimized [local count: 536870913]: __builtin_memset (z_9(D), 0, 8); _17 = *x_11(D); _18 = *y_12(D); _19 = _17 * _18; _20 = _19 + 0.0; *z_9(D) = _20; return; It would be beneficial for all frontends if the use of __builtin_memset() to zero out accumulators would be be considered as !HONOR_SIGNED_ZEROS at least during PRE pass in the middle-end. If that would complicate things, then easier solution is to add special case in gfortran frontend-passes that simply transforms expression to drop accumulator: z[0] = x[0] * y[0]; * side note, in C the redundant __builtin_memset() does not get optimized out, unlike in gfortran "zero" expr version. Might be middle-end optimization passes ordering issue. At least PRE pass does take accumulator zeroing into account.
[Bug fortran/110888] Missing optimization for trivial MATMUL cases, requires -fno-signed-zeros
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110888 Thomas Koenig changed: What|Removed |Added Component|middle-end |fortran --- Comment #4 from Thomas Koenig --- Hm, on second thoughts, signed zeros are an issue, resetting to Fortran. Generally, we are in an intrinsic, so we can do whatever we please (we certainly do in the library case, and this is expected behavior). Having -ffast-math applied locally to the BLOCK that the matmul is executed in would be a possibility.
[Bug fortran/110888] Missing optimization for trivial MATMUL cases, requires -fno-signed-zeros
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110888 Jerry DeLisle changed: What|Removed |Added CC||jvdelisle at gcc dot gnu.org, ||tkoenig at gcc dot gnu.org --- Comment #2 from Jerry DeLisle --- Copying Thomas on this and adding myself.
[Bug fortran/110888] Missing optimization for trivial MATMUL cases, requires -fno-signed-zeros
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110888 --- Comment #1 from Rimvydas (RJ) --- Created attachment 55680 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55680=edit possible fix With this patch an extra register is freed and compiler produces expected code on x86_64: movsd (%rdi), %xmm0 mulsd (%rsi), %xmm0 movsd %xmm0, (%rdx) ret Patch could be expanded to consider inlining trivial matmul cases even for known arrays of size 1 with rank > 2.