From: Xianmiao Qu <cooper.qu@linux.alibaba.com>
To: gcc-patches@gcc.gnu.org, christoph.muellner@vrull.eu,
jeffreyalaw@gmail.com, kito.cheng@sifive.com
Cc: Xianmiao Qu <cooper.qu@linux.alibaba.com>
Subject: [PATCH 1/1] riscv: thead: Fix ICE when enable XTheadMemPair ISA extension.
Date: Tue, 11 Jul 2023 23:39:49 +0800 [thread overview]
Message-ID: <20230711153949.6676-1-cooper.qu@linux.alibaba.com> (raw)
The frame related load/store instructions should not been
scheduled bewteen echo other, and the REG_FRAME_RELATED_EXPR
expression note should should be added to those instructions
to prevent this.
This bug cause ICE during GCC bootstap, and it will also ICE
in the simplified case mempair-4.c, compilation fails with:
during RTL pass: dwarf2
theadmempair-4.c:20:1: internal compiler error: in dwarf2out_frame_debug_cfa_offset, at dwarf2cfi.cc:1376
0xa8c017 dwarf2out_frame_debug_cfa_offset
../../../gcc/gcc/dwarf2cfi.cc:1376
0xa8c017 dwarf2out_frame_debug
../../../gcc/gcc/dwarf2cfi.cc:2285
0xa8c017 scan_insn_after
../../../gcc/gcc/dwarf2cfi.cc:2726
0xa8cc97 scan_trace
../../../gcc/gcc/dwarf2cfi.cc:2893
0xa8d84d create_cfi_notes
../../../gcc/gcc/dwarf2cfi.cc:2933
0xa8d84d execute_dwarf2_frame
../../../gcc/gcc/dwarf2cfi.cc:3309
0xa8d84d execute
../../../gcc/gcc/dwarf2cfi.cc:3799
gcc/ChangeLog:
* config/riscv/thead.cc (th_mempair_save_regs): Add
REG_FRAME_RELATED_EXPR note for mempair instuctions.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/xtheadmempair-4.c: New test.
---
gcc/config/riscv/thead.cc | 6 +++--
.../gcc.target/riscv/xtheadmempair-4.c | 26 +++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c
diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc
index 75203805310..2df709226f9 100644
--- a/gcc/config/riscv/thead.cc
+++ b/gcc/config/riscv/thead.cc
@@ -366,10 +366,12 @@ th_mempair_save_regs (rtx operands[4])
{
rtx set1 = gen_rtx_SET (operands[0], operands[1]);
rtx set2 = gen_rtx_SET (operands[2], operands[3]);
+ rtx dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
rtx insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set1, set2)));
RTX_FRAME_RELATED_P (insn) = 1;
- add_reg_note (insn, REG_CFA_OFFSET, copy_rtx (set1));
- add_reg_note (insn, REG_CFA_OFFSET, copy_rtx (set2));
+ XVECEXP (dwarf, 0, 0) = copy_rtx (set1);
+ XVECEXP (dwarf, 0, 1) = copy_rtx (set2);
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf);
}
/* Similar like riscv_restore_reg, but restores two registers from memory
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c b/gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c
new file mode 100644
index 00000000000..d653f056ef4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Oz" "-Os" "-flto" } } */
+/* { dg-options "-march=rv64gc_xtheadmempair -O2 -g -mtune=thead-c906" { target { rv64 } } } */
+/* { dg-options "-march=rv32gc_xtheadmempair -O2 -g -mtune=thead-c906" { target { rv32 } } } */
+
+void a();
+void b(char *);
+void m_fn1(int);
+int e;
+
+int foo(int ee, int f, int g) {
+ char *h = (char *)__builtin_alloca(1);
+ b(h);
+ b("");
+ int i = ee;
+ e = g;
+ m_fn1(f);
+ a();
+ e = i;
+}
+
+/* { dg-final { scan-assembler-times "th.ldd\t" 3 { target { rv64 } } } } */
+/* { dg-final { scan-assembler-times "th.sdd\t" 3 { target { rv64 } } } } */
+
+/* { dg-final { scan-assembler-times "th.lwd\t" 3 { target { rv32 } } } } */
+/* { dg-final { scan-assembler-times "th.swd\t" 3 { target { rv32 } } } } */
--
2.17.1
next reply other threads:[~2023-07-11 15:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 15:39 Xianmiao Qu [this message]
2023-07-11 15:42 ` Christoph Müllner
2023-07-11 15:51 ` Kito Cheng
2023-07-11 16:02 ` Christoph Müllner
2023-07-12 6:38 ` Xianmiao Qu
2023-07-12 7:07 ` Kito Cheng
2023-07-12 7:11 ` Philipp Tomsich
2023-07-12 7:18 ` Kito Cheng
2023-07-12 7:19 ` Philipp Tomsich
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=20230711153949.6676-1-cooper.qu@linux.alibaba.com \
--to=cooper.qu@linux.alibaba.com \
--cc=christoph.muellner@vrull.eu \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=kito.cheng@sifive.com \
/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).