From patchwork Tue Dec 26 22:37:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 183381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1130479dyb; Tue, 26 Dec 2023 14:39:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpsqqL5b1zZdNxFPHL7gBrSwAeVr8hMQveKq5wPQNQxmkgdsGXnMeH5lvHRiouDqV9OxR7 X-Received: by 2002:a05:6214:caf:b0:67f:40eb:bfa7 with SMTP id s15-20020a0562140caf00b0067f40ebbfa7mr13144755qvs.48.1703630357330; Tue, 26 Dec 2023 14:39:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703630357; cv=pass; d=google.com; s=arc-20160816; b=TcTfdNvjQEjsdkXyE9IWLcpu017ghSZcbhOcq1c36xNLg04My5RXpdgog+QkSfUmZW 6rr4ACViYovdoYzba3ZWn2s1EaA9kgn/Bhwj7DBSM81T1MTU7EzzUoiz3kf/3oaEWzdj UOtGDxJ4HeguG/Xj/IoWZbwr+yQrExbz9MmreTps54eRlYO4OESb+FByzusp2QpxAi0b 6tUsYUuIa2XvPdlnjG0dwpZdgxYDHfSKl7eGUCA2vnglFw5vmALU1WTy7Ftf92zjJzDi TTnfLssREFsf7kxxyhu8tnDIRXP7WVHO51Esrv803G5ReDZJSah8pUxuXJvxaWv2IxS0 5ZeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=fhb96essFxQkassxcBpQT1ZqdzKQ7lyfkUoK3qdxJV0=; fh=lAZEJv+juT1q6RYyAreaw+ZnRPAcRoheJ20Uybha2qY=; b=ly3weOKwq+d0QASrMssQVNdkZPd2AK2/OEFhP0ScE8w//BMeUHG+dANyum0lY+odiP WJbZqxPtBJs4S0CnvZ/THtzDmls0sRmNd4KmidjzCTymlIW/9ANbx3UeCyEStqj+D1qW TKBygXWgtm4yU4qp2jx+jJpJB5xR1prsuVKv0CrYj+OdTXi9ZoHh/LPqiiQTMVlwYFzr rK9vPQU+rMqkQVSVCtU22VGB/LZn1UFyWeW2stSBQqe1fb0iJbJesvKFxp5mrZh6YCEX b2iOdvtO6fDdWY9QBvASc6TRdT82hYJTzpEbjWzUEgLuoN+iZrDomoEA0Q7tfgKfPhNB iOcw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b="iJcg/8eZ"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y2-20020a0ce042000000b0067f87fc5e9bsi12063928qvk.136.2023.12.26.14.39.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 14:39:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b="iJcg/8eZ"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E3D4385828F for ; Tue, 26 Dec 2023 22:39:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786385905231579401 X-GMAIL-MSGID: 1786385905231579401 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) + ; +}