[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-07-04 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

Xi Ruoyao  changed:

   What|Removed |Added

   Target Milestone|13.0|12.2

--- Comment #14 from Xi Ruoyao  ---
Though the bootstrap failure is a 13 regression, the code generation issue has
been already haunting 12.1.  It also breaks building GCC 13 on a system with
GCC 12.1 and --disable-bootstrap.

Change target milestone to 12.2 so it will show up on list of PRs fixed in
12.2.

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread xry111 at mengyan1223 dot wang via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

Xi Ruoyao  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|UNCONFIRMED |RESOLVED

--- Comment #13 from Xi Ruoyao  ---
Fixed for trunk and gcc-12.

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #11 from CVS Commits  ---
The master branch has been updated by Xi Ruoyao :

https://gcc.gnu.org/g:020b7d98589bbc928b5a66b1ed56b42af8791355

commit r13-1319-g020b7d98589bbc928b5a66b1ed56b42af8791355
Author: Xi Ruoyao 
Date:   Tue Jun 28 16:00:14 2022 +0800

loongarch: exclude LARCH_PROLOGUE_TEMP from SIBCALL_REGS [PR 106096]

The epilogue may clobber LARCH_PROLOGUE_TEMP ($r13/$t1), so it cannot be
used for sibcalls.

gcc/ChangeLog:

PR target/106096
* config/loongarch/loongarch.h (REG_CLASS_CONTENTS): Exclude
$r13 from SIBCALL_REGS.
* config/loongarch/loongarch.cc (loongarch_regno_to_class):
Change $r13 to JIRL_REGS.

gcc/testsuite/ChangeLog:

PR target/106096
* g++.target/loongarch/loongarch.exp: New test support file.
* g++.target/loongarch/pr106096.C: New test.

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #12 from CVS Commits  ---
The releases/gcc-12 branch has been updated by Xi Ruoyao :

https://gcc.gnu.org/g:8e230a3c02641792d87252bff7f7554e46da2c25

commit r12-8520-g8e230a3c02641792d87252bff7f7554e46da2c25
Author: Xi Ruoyao 
Date:   Tue Jun 28 16:00:14 2022 +0800

loongarch: exclude LARCH_PROLOGUE_TEMP from SIBCALL_REGS [PR 106096]

The epilogue may clobber LARCH_PROLOGUE_TEMP ($r13/$t1), so it cannot be
used for sibcalls.

gcc/ChangeLog:

PR target/106096
* config/loongarch/loongarch.h (REG_CLASS_CONTENTS): Exclude
$r13 from SIBCALL_REGS.
* config/loongarch/loongarch.cc (loongarch_regno_to_class):
Change $r13 to JIRL_REGS.

gcc/testsuite/ChangeLog:

PR target/106096
* g++.target/loongarch/loongarch.exp: New test support file.
* g++.target/loongarch/pr106096.C: New test.

(cherry picked from commit 020b7d98589bbc928b5a66b1ed56b42af8791355)

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread chenglulu at loongson dot cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #10 from chenglulu  ---
(In reply to Xi Ruoyao from comment #9)
> Created attachment 53214 [details]
> patch removing r13 from SIBCALL_REGS
> 
> I'm testing this patch now.
> 
> I suggest to apply this for trunk and gcc-12 branch first (as gcc-12 also
> miscompiles the test case).
> 
> Then if the reordering of RA preference can improve performance, you may
> apply it later (and also adjust the changes in this patch again).

OK!

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread xry111 at mengyan1223 dot wang via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #9 from Xi Ruoyao  ---
Created attachment 53214
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53214=edit
patch removing r13 from SIBCALL_REGS

I'm testing this patch now.

I suggest to apply this for trunk and gcc-12 branch first (as gcc-12 also
miscompiles the test case).

Then if the reordering of RA preference can improve performance, you may apply
it later (and also adjust the changes in this patch again).

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread chenglulu at loongson dot cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #8 from chenglulu  ---
(In reply to Xi Ruoyao from comment #6)
> (In reply to chenglulu from comment #5)
> > Created attachment 53213 [details]
> > Modify the allocation order of caller saved registers.
> 
> I think we need to completely prevent LARCH_PROLOGUE_TEMP from being used
> for sibcall:
> 
> diff --git a/gcc/config/loongarch/loongarch.h
> b/gcc/config/loongarch/loongarch.h
> index 4d107a42209..f9de9a6e4fb 100644
> --- a/gcc/config/loongarch/loongarch.h
> +++ b/gcc/config/loongarch/loongarch.h
> @@ -511,7 +511,7 @@ enum reg_class
>  #define REG_CLASS_CONTENTS \
>  {  \
>{ 0x, 0x, 0x },  /* NO_REGS  */  \
> -  { 0x001ff000, 0x, 0x },  /* SIBCALL_REGS  */ \
> +  { 0x001fd000, 0x, 0x },  /* SIBCALL_REGS  */ \
>{ 0xff90, 0x, 0x },  /* JIRL_REGS  */\
>{ 0xfffc, 0x, 0x },  /* CSR_REGS  */ \
>{ 0x, 0x, 0x },  /* GR_REGS  */  \
> 
> Or even if LARCH_PROLOGUE_TEMP is less preferred, the register allocator may
> still use it for sibcall and blow something up again.
> 
This solved my doubt. ^v^

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread xry111 at mengyan1223 dot wang via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #7 from Xi Ruoyao  ---
(In reply to Xi Ruoyao from comment #6)
> (In reply to chenglulu from comment #5)
> > Created attachment 53213 [details]
> > Modify the allocation order of caller saved registers.
> 
> I think we need to completely prevent LARCH_PROLOGUE_TEMP from being used
> for sibcall

For example, the RISC-V change explicitly exclude x5 (their temp for epilogue):

https://gcc.gnu.org/legacy-ml/gcc-patches/2019-10/msg01228.html

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread xry111 at mengyan1223 dot wang via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #6 from Xi Ruoyao  ---
(In reply to chenglulu from comment #5)
> Created attachment 53213 [details]
> Modify the allocation order of caller saved registers.

I think we need to completely prevent LARCH_PROLOGUE_TEMP from being used for
sibcall:

diff --git a/gcc/config/loongarch/loongarch.h
b/gcc/config/loongarch/loongarch.h
index 4d107a42209..f9de9a6e4fb 100644
--- a/gcc/config/loongarch/loongarch.h
+++ b/gcc/config/loongarch/loongarch.h
@@ -511,7 +511,7 @@ enum reg_class
 #define REG_CLASS_CONTENTS \
 {  \
   { 0x, 0x, 0x },  /* NO_REGS  */  \
-  { 0x001ff000, 0x, 0x },  /* SIBCALL_REGS  */ \
+  { 0x001fd000, 0x, 0x },  /* SIBCALL_REGS  */ \
   { 0xff90, 0x, 0x },  /* JIRL_REGS  */\
   { 0xfffc, 0x, 0x },  /* CSR_REGS  */ \
   { 0x, 0x, 0x },  /* GR_REGS  */  \

Or even if LARCH_PROLOGUE_TEMP is less preferred, the register allocator may
still use it for sibcall and blow something up again.

(Above is for $r13, if you want to use $r12 instead as LARCH_PROLOGUE_TEMP you
need to adjust it.)

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-28 Thread chenglulu at loongson dot cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

--- Comment #5 from chenglulu  ---
Created attachment 53213
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53213=edit
Modify the allocation order of caller saved registers.

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-27 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |13.0

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-27 Thread xry111 at mengyan1223 dot wang via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

Xi Ruoyao  changed:

   What|Removed |Added

  Known to work|12.1.0  |

--- Comment #4 from Xi Ruoyao  ---
Remove "known to work" because 12.1.0 miscompiles the test case too.

[Bug target/106096] [13 regression] ICE building stage 2 libgcc on loongarch64-linux-gnu because stage 2 gcc is miscompiled

2022-06-27 Thread xry111 at mengyan1223 dot wang via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106096

Xi Ruoyao  changed:

   What|Removed |Added

  Build|loongarch64-linux-gnu   |
Summary|[13 regression] ICE |[13 regression] ICE
   |building stage 2 libgcc on  |building stage 2 libgcc on
   |loongarch64-linux-gnu since |loongarch64-linux-gnu
   |r13-911 |because stage 2 gcc is
   ||miscompiled
   Host|loongarch64-linux-gnu   |

--- Comment #3 from Xi Ruoyao  ---
(In reply to Xi Ruoyao from comment #2)
> Created attachment 53208 [details]
> reduced testcase

For this testcase GCC generates:

.L20:
lu12i.w $r13,4096>>12   # 0x1000
add.d   $r3,$r3,$r13
ld.d$r1,$r3,24
or  $r4,$r23,$r0
ld.d$r23,$r3,16
la.local$r5,b
addi.d  $r3,$r3,32
jr  $r13