public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Lulu Cheng <chenglulu@loongson.cn>
Cc: gcc-patches@gcc.gnu.org, WANG Xuerui <i@xen0n.name>,
	Chenghua Xu <xuchenghua@loongson.cn>,
	Yujie Yang <yangyujie@loongson.cn>,
	Mike Stump <mikestump@comcast.net>
Subject: Re: [PATCH 0/2] LoongArch: testsuite: Fix tests related to stack
Date: Mon, 06 Mar 2023 13:59:15 +0800	[thread overview]
Message-ID: <bad13cffc46507dd8e235796c154d2fcc05c0d87.camel@xry111.site> (raw)
In-Reply-To: <f98e9d550f35c8bf41b71cb376e49056b581d553.camel@xry111.site>

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

  reply	other threads:[~2023-03-06  5:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bad13cffc46507dd8e235796c154d2fcc05c0d87.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=chenglulu@loongson.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=i@xen0n.name \
    --cc=mikestump@comcast.net \
    --cc=xuchenghua@loongson.cn \
    --cc=yangyujie@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).