From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 94DE63858430 for ; Tue, 26 Dec 2023 22:38:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94DE63858430 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 94DE63858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703630318; cv=none; b=X5m25Wjp1Mj9nqVV2IeVle4EwWbJ2xOv9gA9NAHVuDjxEyOfsYnZz+h5//1JkZTlPVBuCGMWBYRiEg4Gh7vvUtsKN6C79Fi01GvcP85XiD9ahH7cgZqVOb6Q0WAVrFIQZXPXx+v04ayQeeibv9eQq3v2gNwfcD2gXPRH47fis80= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703630318; c=relaxed/simple; bh=xvWSpPzka9j4lJ5/7PlwxTni5ov3J2iTcfaWD5+l314=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hjX6qmDzXmaGwnwVA91mDMmcTv9oPDI8ULsUU36gop4wqdDVFe0LASAZgvvJG2ynlYztFELYuShcetXacEvNxXj/mmPlsVmi8FzCigp/C3ag5E8atLokEAAlbZrL0aNXUnUWfL+TX1iHDJ8cSVH1zWy00EdmeuHz9dQBbmyI3uY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1703630312; bh=xvWSpPzka9j4lJ5/7PlwxTni5ov3J2iTcfaWD5+l314=; h=From:To:Cc:Subject:Date:From; b=iJcg/8eZANBxkD1dFP9y1CESja1ZvwDeUAdXfPUqXoUFF0daHTYQcP5iu3jG4+9PK l4ELR6GfdFMGPu7dnNKStg4h/KFbzfiS6BAbF5PEGGs/MBLQGyvFaepmfbpnSnjAtA RlXzQuZxiRLDlcizei8nPY2yK4r1kUhgqTGssLUo= Received: from stargazer.. (unknown [IPv6:240e:358:11e8:b100:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 30FD96711C; Tue, 26 Dec 2023 17:38:28 -0500 (EST) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, c@jia.je, Xi Ruoyao Subject: [PATCH] LoongArch: Fix infinite secondary reloading of FCCmode [PR113148] Date: Wed, 27 Dec 2023 06:37:20 +0800 Message-ID: <20231226223818.128525-1-xry111@xry111.site> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The GCC internal doc says: X might be a pseudo-register or a 'subreg' of a pseudo-register, which could either be in a hard register or in memory. Use 'true_regnum' to find out; it will return -1 if the pseudo is in memory and the hard register number if it is in a register. So "MEM_P (x)" is not enough for checking if we are reloading from/to the memory. This bug has caused reload pass to stall and finally ICE complaining with "maximum number of generated reload insns per insn achieved", since r14-6814. Check if "true_regnum (x)" is -1 besides "MEM_P (x)" to fix the issue. gcc/ChangeLog: PR target/113148 * config/loongarch/loongarch.cc (loongarch_secondary_reload): Check if regno == -1 besides MEM_P (x) for reloading FCCmode from/to FPR to/from memory. gcc/testsuite/ChangeLog: PR target/113148 * gcc.target/loongarch/pr113148.c: New test. --- Bootstrapped & regtested on loongarch64-linux-gnu. Ok for trunk? gcc/config/loongarch/loongarch.cc | 3 +- gcc/testsuite/gcc.target/loongarch/pr113148.c | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/pr113148.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 5ffd06ce9be..c0a0af3dda5 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -6951,7 +6951,8 @@ loongarch_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x, return NO_REGS; } - if (reg_class_subset_p (rclass, FP_REGS) && MEM_P (x)) + if (reg_class_subset_p (rclass, FP_REGS) + && (regno == -1 || MEM_P (x))) return GR_REGS; return NO_REGS; diff --git a/gcc/testsuite/gcc.target/loongarch/pr113148.c b/gcc/testsuite/gcc.target/loongarch/pr113148.c new file mode 100644 index 00000000000..cf48e552053 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/pr113148.c @@ -0,0 +1,44 @@ +/* PR 113148: ICE caused by infinite reloading */ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=la464 -mfpu=64 -mabi=lp64d" } */ + +struct bound +{ + double max; +} drawQuadrant_bound; +double w4, innerXfromXY_y, computeBound_right_0; +struct arc_def +{ + double w, h; + double a0, a1; +}; +static void drawQuadrant (struct arc_def *); +static void +computeBound (struct arc_def *def, struct bound *bound) +{ + double ellipsex_1, ellipsex_0; + bound->max = def->a1 ?: __builtin_sin (w4) * def->h; + if (def->a0 == 5 && def->w == def->h) + ; + else + ellipsex_0 = def->a0 == 0.0 ?: __builtin_cos (w4); + if (def->a1 == 5 && def->w == def->h) + ellipsex_1 = bound->max; + __builtin_sqrt (ellipsex_1 * innerXfromXY_y * innerXfromXY_y * w4); + computeBound_right_0 = ellipsex_0; +} +void +drawArc () +{ + struct arc_def foo; + for (;;) + drawQuadrant (&foo); +} +void +drawQuadrant (struct arc_def *def) +{ + int y, miny; + computeBound (def, &drawQuadrant_bound); + while (y >= miny) + ; +} -- 2.43.0