public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
@ 2023-03-03  8:40 Xi Ruoyao
  2023-03-03  8:40 ` [PATCH 1/2] LoongArch: testsuite: Disable stack protector for some tests Xi Ruoyao
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-03  8:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: WANG Xuerui, Lulu Cheng, Chenghua Xu, Yujie Yang, Xi Ruoyao

Some trivial test case fixes.  Ok for trunk?

Xi Ruoyao (2):
  LoongArch: testsuite: Disable stack protector for some tests
  LoongArch: testsuite: Adjust stack offsets in stack-check-cfa tests

 gcc/testsuite/gcc.target/loongarch/prolog-opt.c        | 2 +-
 gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c | 4 ++--
 gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.39.2


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

* [PATCH 1/2] LoongArch: testsuite: Disable stack protector for some tests
  2023-03-03  8:40 [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Xi Ruoyao
@ 2023-03-03  8:40 ` Xi Ruoyao
  2023-03-03  8:40 ` [PATCH 2/2] LoongArch: testsuite: Adjust stack offsets in stack-check-cfa tests Xi Ruoyao
  2023-03-03 16:21 ` [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Mike Stump
  2 siblings, 0 replies; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-03  8:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: WANG Xuerui, Lulu Cheng, Chenghua Xu, Yujie Yang, Xi Ruoyao

Stack protector will affect stack layout and break the expectation of
these tests, causing test failures if GCC is configured with
--enable-default-ssp.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/prolog-opt.c (dg-options): Add
	-fno-stack-protector.
	* gcc.target/loongarch/stack-check-cfa-1.c (dg-options):
	Likewise.
	* gcc.target/loongarch/stack-check-cfa-2.c (dg-options):
	Likewise.
---
 gcc/testsuite/gcc.target/loongarch/prolog-opt.c        | 2 +-
 gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c | 2 +-
 gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
index 0470a1f1eee..e6a64263384 100644
--- a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
+++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
@@ -1,7 +1,7 @@
 /* Test that LoongArch backend stack drop operation optimized.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mabi=lp64d" } */
+/* { dg-options "-O2 -mabi=lp64d -fno-stack-protector" } */
 /* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */
 
 extern int printf (char *, ...);
diff --git a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
index f0c6877fc25..3533fe7b685 100644
--- a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
+++ b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables" } */
+/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables -fno-stack-protector" } */
 /* { dg-require-effective-target supports_stack_clash_protection } */
 /* { dg-skip-if "" { *-*-* } { "-fstack-check" } { "" } } */
 
diff --git a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c
index c6e07bc561a..e5e711105ac 100644
--- a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c
+++ b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables" } */
+/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -funwind-tables -fno-stack-protector" } */
 /* { dg-require-effective-target supports_stack_clash_protection } */
 /* { dg-skip-if "" { *-*-* } { "-fstack-check" } { "" } } */
 
-- 
2.39.2


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

* [PATCH 2/2] LoongArch: testsuite: Adjust stack offsets in stack-check-cfa tests
  2023-03-03  8:40 [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Xi Ruoyao
  2023-03-03  8:40 ` [PATCH 1/2] LoongArch: testsuite: Disable stack protector for some tests Xi Ruoyao
@ 2023-03-03  8:40 ` Xi Ruoyao
  2023-03-03 16:21 ` [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Mike Stump
  2 siblings, 0 replies; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-03  8:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: WANG Xuerui, Lulu Cheng, Chenghua Xu, Yujie Yang, Xi Ruoyao

Once upon the time we used to save two registers unnecessarily, costing
16 bytes.  Now the issue seems fixed (not sure by which commit though),
adjust the stack offsets to reflex the change.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/stack-check-cfa-1.c (dg-final): Adjust
	expected stack offset.
	* gcc.target/loongarch/stack-check-cfa-2.c (dg-final): Likewise.
---
 gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c | 2 +-
 gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
index 3533fe7b685..cd72154f46c 100644
--- a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
+++ b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-1.c
@@ -6,7 +6,7 @@
 #define SIZE 128*1024
 #include "stack-check-prologue.h"
 
-/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 131088} 1 } } */
+/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 131072} 1 } } */
 /* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 0} 1 } } */
 
 /* Checks that the CFA notes are correct for every sp adjustment.  */
diff --git a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c
index e5e711105ac..3e5ca05b2da 100644
--- a/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c
+++ b/gcc/testsuite/gcc.target/loongarch/stack-check-cfa-2.c
@@ -6,7 +6,7 @@
 #define SIZE 1280*1024 + 512
 #include "stack-check-prologue.h"
 
-/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 1311248} 1 } } */
+/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 1311232} 1 } } */
 /* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 0} 1 } } */
 
 /* Checks that the CFA notes are correct for every sp adjustment.  */
-- 
2.39.2


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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-03  8:40 [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Xi Ruoyao
  2023-03-03  8:40 ` [PATCH 1/2] LoongArch: testsuite: Disable stack protector for some tests Xi Ruoyao
  2023-03-03  8:40 ` [PATCH 2/2] LoongArch: testsuite: Adjust stack offsets in stack-check-cfa tests Xi Ruoyao
@ 2023-03-03 16:21 ` Mike Stump
  2023-03-05 16:21   ` Xi Ruoyao
  2 siblings, 1 reply; 13+ messages in thread
From: Mike Stump @ 2023-03-03 16:21 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-patches, WANG Xuerui, Lulu Cheng, Chenghua Xu, Yujie Yang

On Mar 3, 2023, at 12:40 AM, Xi Ruoyao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> Some trivial test case fixes.  Ok for trunk?

Ok.

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-03 16:21 ` [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Mike Stump
@ 2023-03-05 16:21   ` Xi Ruoyao
  2023-03-06  1:15     ` Lulu Cheng
  0 siblings, 1 reply; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-05 16:21 UTC (permalink / raw)
  To: Lulu Cheng; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump

On Fri, 2023-03-03 at 08:21 -0800, Mike Stump wrote:
> On Mar 3, 2023, at 12:40 AM, Xi Ruoyao via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> > 
> > Some trivial test case fixes.  Ok for trunk?
> 
> Ok.

Lulu: if you don't object I'll push these two in this week.

I tried to bisect for the exact point where the test cases are broken,
but it turns out they are broken the first day committed (r13-4401).  As
the draft of r13-4401 was sent in Sept 2022 but it's committed in Nov
2022, I can only guess something had changed in the two months and broke
the tests...
-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-05 16:21   ` Xi Ruoyao
@ 2023-03-06  1:15     ` Lulu Cheng
  2023-03-06  2:48       ` Xi Ruoyao
  0 siblings, 1 reply; 13+ messages in thread
From: Lulu Cheng @ 2023-03-06  1:15 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump


在 2023/3/6 上午12:21, Xi Ruoyao 写道:
> On Fri, 2023-03-03 at 08:21 -0800, Mike Stump wrote:
>> On Mar 3, 2023, at 12:40 AM, Xi Ruoyao via Gcc-patches
>> <gcc-patches@gcc.gnu.org> wrote:
>>> Some trivial test case fixes.  Ok for trunk?
>> Ok.
> Lulu: if you don't object I'll push these two in this week.
>
> I tried to bisect for the exact point where the test cases are broken,
> but it turns out they are broken the first day committed (r13-4401).  As
> the draft of r13-4401 was sent in Sept 2022 but it's committed in Nov
> 2022, I can only guess something had changed in the two months and broke
> the tests...

Sorry for the late reply, the first patch I think is fine. But I haven't 
reproduced the problem of the second mail.

Is there any special option in the configuration?


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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  1:15     ` Lulu Cheng
@ 2023-03-06  2:48       ` Xi Ruoyao
  2023-03-06  3:16         ` Xi Ruoyao
  0 siblings, 1 reply; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-06  2:48 UTC (permalink / raw)
  To: Lulu Cheng; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump

On Mon, 2023-03-06 at 09:15 +0800, Lulu Cheng wrote:
> 
> 在 2023/3/6 上午12:21, Xi Ruoyao 写道:
> > On Fri, 2023-03-03 at 08:21 -0800, Mike Stump wrote:
> > > On Mar 3, 2023, at 12:40 AM, Xi Ruoyao via Gcc-patches
> > > <gcc-patches@gcc.gnu.org> wrote:
> > > > Some trivial test case fixes.  Ok for trunk?
> > > Ok.
> > Lulu: if you don't object I'll push these two in this week.
> > 
> > I tried to bisect for the exact point where the test cases are broken,
> > but it turns out they are broken the first day committed (r13-4401).  As
> > the draft of r13-4401 was sent in Sept 2022 but it's committed in Nov
> > 2022, I can only guess something had changed in the two months and broke
> > the tests...
> 
> Sorry for the late reply, the first patch I think is fine. But I haven't 
> reproduced the problem of the second mail.
> 
> Is there any special option in the configuration?

Oh some strange thing might be happening... I'll try to figure out what
has caused the behavior difference.
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  2:48       ` Xi Ruoyao
@ 2023-03-06  3:16         ` Xi Ruoyao
  2023-03-06  5:59           ` Xi Ruoyao
  0 siblings, 1 reply; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-06  3:16 UTC (permalink / raw)
  To: Lulu Cheng; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump

On Mon, 2023-03-06 at 10:48 +0800, Xi Ruoyao wrote:
> On Mon, 2023-03-06 at 09:15 +0800, Lulu Cheng wrote:
> > 
> > 在 2023/3/6 上午12:21, Xi Ruoyao 写道:
> > > On Fri, 2023-03-03 at 08:21 -0800, Mike Stump wrote:
> > > > On Mar 3, 2023, at 12:40 AM, Xi Ruoyao via Gcc-patches
> > > > <gcc-patches@gcc.gnu.org> wrote:
> > > > > Some trivial test case fixes.  Ok for trunk?
> > > > Ok.
> > > Lulu: if you don't object I'll push these two in this week.
> > > 
> > > I tried to bisect for the exact point where the test cases are broken,
> > > but it turns out they are broken the first day committed (r13-4401).  As
> > > the draft of r13-4401 was sent in Sept 2022 but it's committed in Nov
> > > 2022, I can only guess something had changed in the two months and broke
> > > the tests...
> > 
> > Sorry for the late reply, the first patch I think is fine. But I haven't 
> > reproduced the problem of the second mail.
> > 
> > Is there any special option in the configuration?
> 
> Oh some strange thing might be happening... I'll try to figure out what
> has caused the behavior difference.

Oh no, the difference is caused by --enable-default-pie.

Maybe I should just add -fno-PIE for the dg-options.  But now I'm still
puzzled: why would -fPIE affect code generation on LoongArch?  AFAIK all
the code we are generating is position independent (at least for now).
> 

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  3:16         ` Xi Ruoyao
@ 2023-03-06  5:59           ` Xi Ruoyao
  2023-03-06  8:02             ` Xi Ruoyao
  0 siblings, 1 reply; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-06  5:59 UTC (permalink / raw)
  To: Lulu Cheng; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump

On Mon, 2023-03-06 at 11:16 +0800, Xi Ruoyao wrote:

/* snip */

> > > Sorry for the late reply, the first patch I think is fine. But I haven't 
> > > reproduced the problem of the second mail.
> > > 
> > > Is there any special option in the configuration?
> > 
> > Oh some strange thing might be happening... I'll try to figure out what
> > has caused the behavior difference.
> 
> Oh no, the difference is caused by --enable-default-pie.
> 
> Maybe I should just add -fno-PIE for the dg-options.  But now I'm still
> puzzled: why would -fPIE affect code generation on LoongArch?  AFAIK all
> the code we are generating is position independent (at least for now).

Without -fPIE, the compiler stores a register with no reason:

$ cat t.c
int test(int x)
{
	char buf[128 << 10];
	return buf[x];
}
$ ./gcc/cc1 t.c -nostdinc  -O2 -fdump-rtl-all -o- 2>/dev/null | grep test: -A20
test:
.LFB0 = .
	lu12i.w	$r13,-135168>>12			# 0xfffffffffffdf000
	ori	$r13,$r13,4080
	add.d	$r3,$r3,$r13
.LCFI0 = .
	lu12i.w	$r12,-131072>>12			# 0xfffffffffffe0000
	lu12i.w	$r13,131072>>12			# 0x20000
	add.d	$r13,$r13,$r12
	addi.d	$r12,$r3,16
	add.d	$r12,$r13,$r12
	lu12i.w	$r13,131072>>12			# 0x20000
	st.d	$r12,$r3,8
	ori	$r13,$r13,16
	ldx.b	$r4,$r12,$r4
	add.d	$r3,$r3,$r13
.LCFI1 = .
	jr	$r1
.LFE0:
	.size	test, .-test
	.section	.eh_frame,"aw",@progbits

Note the "st.d	$r12,$r3,8" instruction is completely meaningless.

The t.c.300r.ira dump contains some "interesting" thing:

Pass 0 for finding pseudo/allocno costs

    a0 (r87,l0) best GR_REGS, allocno GR_REGS
    a1 (r84,l0) best NO_REGS, allocno NO_REGS
    a2 (r83,l0) best GR_REGS, allocno GR_REGS

  a0(r87,l0) costs: SIBCALL_REGS:2000,2000 JIRL_REGS:2000,2000 CSR_REGS:2000,2000 GR_REGS:2000,2000 FP_REGS:8000,8000 ALL_REGS:32000,32000 MEM:8000,8000
  a1(r84,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000 CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000 ALL_REGS:1016000,1016000 MEM:1004000,1004000
  a2(r83,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000 CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000 ALL_REGS:1008000,1008000 MEM:1004000,1004000


Here r84 is the pseudo register for ($frame - 131072).  Any idea why the
compiler selects "NO_REGS" here?

FWIW RISC-V port suffers the same issue:
https://godbolt.org/z/aPorqj73b.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  5:59           ` Xi Ruoyao
@ 2023-03-06  8:02             ` Xi Ruoyao
  2023-03-06  8:12               ` Lulu Cheng
  0 siblings, 1 reply; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-06  8:02 UTC (permalink / raw)
  To: Lulu Cheng; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump

On Mon, 2023-03-06 at 13:59 +0800, Xi Ruoyao via Gcc-patches wrote:
> On Mon, 2023-03-06 at 11:16 +0800, Xi Ruoyao wrote:
> 
> /* snip */
> 
> > > > Sorry for the late reply, the first patch I think is fine. But I haven't 
> > > > reproduced the problem of the second mail.
> > > > 
> > > > Is there any special option in the configuration?
> > > 
> > > Oh some strange thing might be happening... I'll try to figure out what
> > > has caused the behavior difference.
> > 
> > Oh no, the difference is caused by --enable-default-pie.
> > 
> > Maybe I should just add -fno-PIE for the dg-options.  But now I'm still
> > puzzled: why would -fPIE affect code generation on LoongArch?  AFAIK all
> > the code we are generating is position independent (at least for now).
> 
> Without -fPIE, the compiler stores a register with no reason:

Pushed the first patch as r13-6501.  The second one is dropped and I've
created PR109035 for the "unnecessary store" issue (after some failed
attempts to triage it).

> $ cat t.c
> int test(int x)
> {
>         char buf[128 << 10];
>         return buf[x];
> }
> $ ./gcc/cc1 t.c -nostdinc  -O2 -fdump-rtl-all -o- 2>/dev/null | grep test: -A20
> test:
> .LFB0 = .
>         lu12i.w $r13,-135168>>12                        # 0xfffffffffffdf000
>         ori     $r13,$r13,4080
>         add.d   $r3,$r3,$r13
> .LCFI0 = .
>         lu12i.w $r12,-131072>>12                        # 0xfffffffffffe0000
>         lu12i.w $r13,131072>>12                 # 0x20000
>         add.d   $r13,$r13,$r12
>         addi.d  $r12,$r3,16
>         add.d   $r12,$r13,$r12
>         lu12i.w $r13,131072>>12                 # 0x20000
>         st.d    $r12,$r3,8
>         ori     $r13,$r13,16
>         ldx.b   $r4,$r12,$r4
>         add.d   $r3,$r3,$r13
> .LCFI1 = .
>         jr      $r1
> .LFE0:
>         .size   test, .-test
>         .section        .eh_frame,"aw",@progbits
> 
> Note the "st.d  $r12,$r3,8" instruction is completely meaningless.
> 
> The t.c.300r.ira dump contains some "interesting" thing:
> 
> Pass 0 for finding pseudo/allocno costs
> 
>     a0 (r87,l0) best GR_REGS, allocno GR_REGS
>     a1 (r84,l0) best NO_REGS, allocno NO_REGS
>     a2 (r83,l0) best GR_REGS, allocno GR_REGS
> 
>   a0(r87,l0) costs: SIBCALL_REGS:2000,2000 JIRL_REGS:2000,2000 CSR_REGS:2000,2000 GR_REGS:2000,2000 FP_REGS:8000,8000 ALL_REGS:32000,32000 MEM:8000,8000
>   a1(r84,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000 CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000 ALL_REGS:1016000,1016000 MEM:1004000,1004000
>   a2(r83,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000 CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000 ALL_REGS:1008000,1008000 MEM:1004000,1004000
> 
> 
> Here r84 is the pseudo register for ($frame - 131072).  Any idea why the
> compiler selects "NO_REGS" here?
> 
> FWIW RISC-V port suffers the same issue:
> https://godbolt.org/z/aPorqj73b.


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  8:02             ` Xi Ruoyao
@ 2023-03-06  8:12               ` Lulu Cheng
  2023-03-06  8:18                 ` Xi Ruoyao
  0 siblings, 1 reply; 13+ messages in thread
From: Lulu Cheng @ 2023-03-06  8:12 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump


在 2023/3/6 下午4:02, Xi Ruoyao 写道:
> On Mon, 2023-03-06 at 13:59 +0800, Xi Ruoyao via Gcc-patches wrote:
>> On Mon, 2023-03-06 at 11:16 +0800, Xi Ruoyao wrote:
>>
>> /* snip */
>>
>>>>> Sorry for the late reply, the first patch I think is fine. But I haven't
>>>>> reproduced the problem of the second mail.
>>>>>
>>>>> Is there any special option in the configuration?
>>>> Oh some strange thing might be happening... I'll try to figure out what
>>>> has caused the behavior difference.
>>> Oh no, the difference is caused by --enable-default-pie.
>>>
>>> Maybe I should just add -fno-PIE for the dg-options.  But now I'm still
>>> puzzled: why would -fPIE affect code generation on LoongArch?  AFAIK all
>>> the code we are generating is position independent (at least for now).
>> Without -fPIE, the compiler stores a register with no reason:
> Pushed the first patch as r13-6501.  The second one is dropped and I've
> created PR109035 for the "unnecessary store" issue (after some failed
> attempts to triage it).

Has the first patch been merged into the main branch yet?

I think there is one more test case that needs to be modified:

--- a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
+++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
@@ -1,7 +1,7 @@
  /* Test that LoongArch backend stack drop operation optimized. */

  /* { dg-do compile } */
-/* { dg-options "-O2 -mabi=lp64d" } */
+/* { dg-options "-O2 -mabi=lp64d -fno-stack-protector" } */
  /* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */


>> $ cat t.c
>> int test(int x)
>> {
>>          char buf[128 << 10];
>>          return buf[x];
>> }
>> $ ./gcc/cc1 t.c -nostdinc  -O2 -fdump-rtl-all -o- 2>/dev/null | grep test: -A20
>> test:
>> .LFB0 = .
>>          lu12i.w $r13,-135168>>12                        # 0xfffffffffffdf000
>>          ori     $r13,$r13,4080
>>          add.d   $r3,$r3,$r13
>> .LCFI0 = .
>>          lu12i.w $r12,-131072>>12                        # 0xfffffffffffe0000
>>          lu12i.w $r13,131072>>12                 # 0x20000
>>          add.d   $r13,$r13,$r12
>>          addi.d  $r12,$r3,16
>>          add.d   $r12,$r13,$r12
>>          lu12i.w $r13,131072>>12                 # 0x20000
>>          st.d    $r12,$r3,8
>>          ori     $r13,$r13,16
>>          ldx.b   $r4,$r12,$r4
>>          add.d   $r3,$r3,$r13
>> .LCFI1 = .
>>          jr      $r1
>> .LFE0:
>>          .size   test, .-test
>>          .section        .eh_frame,"aw",@progbits
>>
>> Note the "st.d  $r12,$r3,8" instruction is completely meaningless.
>>
>> The t.c.300r.ira dump contains some "interesting" thing:
>>
>> Pass 0 for finding pseudo/allocno costs
>>
>>      a0 (r87,l0) best GR_REGS, allocno GR_REGS
>>      a1 (r84,l0) best NO_REGS, allocno NO_REGS
>>      a2 (r83,l0) best GR_REGS, allocno GR_REGS
>>
>>    a0(r87,l0) costs: SIBCALL_REGS:2000,2000 JIRL_REGS:2000,2000 CSR_REGS:2000,2000 GR_REGS:2000,2000 FP_REGS:8000,8000 ALL_REGS:32000,32000 MEM:8000,8000
>>    a1(r84,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000 CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000 ALL_REGS:1016000,1016000 MEM:1004000,1004000
>>    a2(r83,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000 CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000 ALL_REGS:1008000,1008000 MEM:1004000,1004000
>>
>>
>> Here r84 is the pseudo register for ($frame - 131072).  Any idea why the
>> compiler selects "NO_REGS" here?
>>
>> FWIW RISC-V port suffers the same issue:
>> https://godbolt.org/z/aPorqj73b.
>


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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  8:12               ` Lulu Cheng
@ 2023-03-06  8:18                 ` Xi Ruoyao
  2023-03-06  8:22                   ` Lulu Cheng
  0 siblings, 1 reply; 13+ messages in thread
From: Xi Ruoyao @ 2023-03-06  8:18 UTC (permalink / raw)
  To: Lulu Cheng; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump

On Mon, 2023-03-06 at 16:12 +0800, Lulu Cheng wrote:
> Has the first patch been merged into the main branch yet?
> 
> I think there is one more test case that needs to be modified:
> 
> --- a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
> +++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
> @@ -1,7 +1,7 @@
>   /* Test that LoongArch backend stack drop operation optimized. */
> 
>   /* { dg-do compile } */
> -/* { dg-options "-O2 -mabi=lp64d" } */
> +/* { dg-options "-O2 -mabi=lp64d -fno-stack-protector" } */
>   /* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */

The first patch contains this hunk.  It's r13-6501 now.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
  2023-03-06  8:18                 ` Xi Ruoyao
@ 2023-03-06  8:22                   ` Lulu Cheng
  0 siblings, 0 replies; 13+ messages in thread
From: Lulu Cheng @ 2023-03-06  8:22 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: gcc-patches, WANG Xuerui, Chenghua Xu, Yujie Yang, Mike Stump


在 2023/3/6 下午4:18, Xi Ruoyao 写道:
> On Mon, 2023-03-06 at 16:12 +0800, Lulu Cheng wrote:
>> Has the first patch been merged into the main branch yet?
>>
>> I think there is one more test case that needs to be modified:
>>
>> --- a/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
>> +++ b/gcc/testsuite/gcc.target/loongarch/prolog-opt.c
>> @@ -1,7 +1,7 @@
>>    /* Test that LoongArch backend stack drop operation optimized. */
>>
>>    /* { dg-do compile } */
>> -/* { dg-options "-O2 -mabi=lp64d" } */
>> +/* { dg-options "-O2 -mabi=lp64d -fno-stack-protector" } */
>>    /* { dg-final { scan-assembler "addi.d\t\\\$r3,\\\$r3,-16" } } */
> The first patch contains this hunk.  It's r13-6501 now.
>
Ok!

Thanks! :-)




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

end of thread, other threads:[~2023-03-06  8:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03  8:40 [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Xi Ruoyao
2023-03-03  8:40 ` [PATCH 1/2] LoongArch: testsuite: Disable stack protector for some tests Xi Ruoyao
2023-03-03  8:40 ` [PATCH 2/2] LoongArch: testsuite: Adjust stack offsets in stack-check-cfa tests Xi Ruoyao
2023-03-03 16:21 ` [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack Mike Stump
2023-03-05 16:21   ` Xi Ruoyao
2023-03-06  1:15     ` Lulu Cheng
2023-03-06  2:48       ` Xi Ruoyao
2023-03-06  3:16         ` Xi Ruoyao
2023-03-06  5:59           ` Xi Ruoyao
2023-03-06  8:02             ` Xi Ruoyao
2023-03-06  8:12               ` Lulu Cheng
2023-03-06  8:18                 ` Xi Ruoyao
2023-03-06  8:22                   ` Lulu Cheng

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).