public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105771] New: matrix partial transposition with -O3
@ 2022-05-30  8:41 franckbehaghel_gcc at protonmail dot com
  2022-05-30  9:14 ` [Bug c/105771] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: franckbehaghel_gcc at protonmail dot com @ 2022-05-30  8:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105771
           Summary: matrix partial transposition with -O3
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: franckbehaghel_gcc at protonmail dot com
  Target Milestone: ---

Created attachment 53051
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53051&action=edit
source

Hello,

The attached code does not produce the same result with -O3 flag enabled.

It seems that gcc reorders operations that should not be in the matrix
transposition operation. The trick here is that the attached code does inplace
partial transposition. 


To reproduce : 
gcc  main0.c  && ./a.out > O0.txt ; gcc main0.c -O3 && ./a.out > O3.txt ;
md5sum O0.txt O3.txt 
0b513fb110f11f0e9b143c53d5b7a634  O0.txt
12be7305e8e96decd579a1e42d45bc46  O3.txt

This behavior is weird as matrix size lower than 16 do not trigger the
suspected bug.

My gcc version is 10.3.1.
I tested with https://godbolt.org/ : It seems to be introduce in Gcc 8.1 as Gcc
7.5 give the correct output. The last gcc 12.1 seems also affected.

Clang is fine and give the right output.

Can someone confirmed ?
Best regards,
Franck

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/105771] matrix partial transposition with -O3
  2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
@ 2022-05-30  9:14 ` pinskia at gcc dot gnu.org
  2022-05-30  9:16 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-30  9:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think you have an aliasing violation here. Does adding -fno-strict-aliasing
fix the issue?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/105771] matrix partial transposition with -O3
  2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
  2022-05-30  9:14 ` [Bug c/105771] " pinskia at gcc dot gnu.org
@ 2022-05-30  9:16 ` pinskia at gcc dot gnu.org
  2022-05-30  9:38 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-30  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the way to fix the code is to do this:
transpose_upper_to_lower (mat,&mat);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/105771] matrix partial transposition with -O3
  2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
  2022-05-30  9:14 ` [Bug c/105771] " pinskia at gcc dot gnu.org
  2022-05-30  9:16 ` pinskia at gcc dot gnu.org
@ 2022-05-30  9:38 ` rguenth at gcc dot gnu.org
  2022-05-30  9:55 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-30  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection, wrong-code
      Known to fail|                            |10.2.0, 11.2.0, 9.4.0
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-05-30

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

main0.c:28:20: optimized: applying unroll and jam with factor 2
main0.c:29:24: optimized: loop with 16 iterations completely unrolled (header
execution count 59700049)
main0.c:45:24: optimized: loop vectorized using 16 byte vectors
main0.c:45:24: optimized: loop turned into non-loop; it never loops
main0.c:41:5: optimized: loop with 3 iterations completely unrolled (header
execution count 59700049)
main0.c:44:20: optimized: loop with 16 iterations completely unrolled (header
execution count 0)

-fno-loop-unroll-and-jam fixes it.  Can't check trunk right now whether it's
fixed.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/105771] matrix partial transposition with -O3
  2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
                   ` (2 preceding siblings ...)
  2022-05-30  9:38 ` rguenth at gcc dot gnu.org
@ 2022-05-30  9:55 ` rguenth at gcc dot gnu.org
  2022-05-30 10:18 ` [Bug c/105771] matrix partial transposition with -O3 since r8-5159-g1cc521f1a824b591 marxin at gcc dot gnu.org
  2022-05-30 11:04 ` franckbehaghel_gcc at protonmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-30  9:55 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |12.1.1

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Not fixed on trunk.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/105771] matrix partial transposition with -O3 since r8-5159-g1cc521f1a824b591
  2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
                   ` (3 preceding siblings ...)
  2022-05-30  9:55 ` rguenth at gcc dot gnu.org
@ 2022-05-30 10:18 ` marxin at gcc dot gnu.org
  2022-05-30 11:04 ` franckbehaghel_gcc at protonmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-05-30 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|matrix partial              |matrix partial
                   |transposition with -O3      |transposition with -O3
                   |                            |since
                   |                            |r8-5159-g1cc521f1a824b591
           Keywords|needs-bisection             |
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r8-5159-g1cc521f1a824b591.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/105771] matrix partial transposition with -O3 since r8-5159-g1cc521f1a824b591
  2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
                   ` (4 preceding siblings ...)
  2022-05-30 10:18 ` [Bug c/105771] matrix partial transposition with -O3 since r8-5159-g1cc521f1a824b591 marxin at gcc dot gnu.org
@ 2022-05-30 11:04 ` franckbehaghel_gcc at protonmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: franckbehaghel_gcc at protonmail dot com @ 2022-05-30 11:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Franck Behaghel <franckbehaghel_gcc at protonmail dot com> ---
Hello,

> Does adding -fno-strict-aliasing fix the issue?
Right, it does. 

> I think you have an aliasing violation here.
I can not say if we have aliasing violation here. My understanding is that AV
happens when mixing pointer type referring to the same address.

>I think the way to fix the code is to do this:
>transpose_upper_to_lower (mat,&mat);
It does not change the result. The issue is still present.

> -fno-loop-unroll-and-jam fixes it.  Can't check trunk right now whether it's fixed.
I can confirm this too.


Regards,
Franck

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-30 11:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30  8:41 [Bug c/105771] New: matrix partial transposition with -O3 franckbehaghel_gcc at protonmail dot com
2022-05-30  9:14 ` [Bug c/105771] " pinskia at gcc dot gnu.org
2022-05-30  9:16 ` pinskia at gcc dot gnu.org
2022-05-30  9:38 ` rguenth at gcc dot gnu.org
2022-05-30  9:55 ` rguenth at gcc dot gnu.org
2022-05-30 10:18 ` [Bug c/105771] matrix partial transposition with -O3 since r8-5159-g1cc521f1a824b591 marxin at gcc dot gnu.org
2022-05-30 11:04 ` franckbehaghel_gcc at protonmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).