From patchwork Fri Aug 9 09:49:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1970882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=SDa6NIDT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgK285Tdlz1ybT for ; Fri, 9 Aug 2024 19:52:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3112385841C for ; Fri, 9 Aug 2024 09:51:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id AE79B3857022 for ; Fri, 9 Aug 2024 09:49:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE79B3857022 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE79B3857022 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723196959; cv=none; b=tMjTwZg4E1jX8/6dN1s5VV8U+i1Hp+K5bn3mmqS1mKW3jud2CCoXzgjp8PoGP5J2WtX0ilx/Ro13Xl2cFcIArZgfD+2u0zu06xJhCTWbIer4lyhSoSDiiobTljAiss8VvLlZeB00FYLkHyOlrXecYsQkCQ7skf0KL31KwPWq0LM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723196959; c=relaxed/simple; bh=ryUwStXHhqY928eybcUzwMzbCSXOMC6hs/vUwIGQO6I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=E53EIf1MSriBN6V3PXi4hSkldc4weeeYFON9/pH/V/VMufgzN0+i0SQBuryRvzFOBVjokm3UxfReb528+RrwZIGYj322H7t0Fp2zunaLB49EkBvxRDEDNC/opXwmCOE5XyCfM1y6m2C608JlDs4qBqh+MT56n8Z45C2jiJZNlm0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4796U22u029459; Fri, 9 Aug 2024 09:49:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:mime-version:to:cc:from:subject:content-type :content-transfer-encoding; s=pp1; bh=Eew3tFSE9zsJgqfbLIc8/zSkUY sdMxUxrCjEgZTjXV4=; b=SDa6NIDTOr8vj/uqQyOLjdxJ5yUImPHXTrJp6AneHp mCTzI7CfEo2puQFcvXA6Pof8EUzannpmlJ34TYzUcHoODv543c280RNCPHtnlGM7 tZo/L26R/Wsx6B6t5XfZ06W7ti8uBxzToJhE2dW7w/YAcUxlUAXlRFkT7z+zrm+p w6C/P9OoUWBoSa+l1Er6JFme9EFVrcD36uR7AcLFToO/05GXFQA3WEZNoAq1h8HK zEaUT68mIbnaqz7CKzNX445GgHAuTn/HEiLekKM/GJb0855DLVLcpS0igAZcFuyb T3pqTr103ssKoAH2ymtnanWQP4yz+diyq2vyVHovOy1g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40vwkcjgen-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Aug 2024 09:49:14 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 4799nDsq011849; Fri, 9 Aug 2024 09:49:13 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40vwkcjgej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Aug 2024 09:49:13 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4797Ul0B024121; Fri, 9 Aug 2024 09:49:12 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 40syvptxcr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Aug 2024 09:49:12 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4799n8fK59703756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Aug 2024 09:49:10 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA1D720040; Fri, 9 Aug 2024 09:49:08 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 235602004D; Fri, 9 Aug 2024 09:49:06 +0000 (GMT) Received: from [9.197.239.15] (unknown [9.197.239.15]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 9 Aug 2024 09:49:05 +0000 (GMT) Message-ID: <55fe76af-a0c5-1066-7b94-022cfcf46556@linux.ibm.com> Date: Fri, 9 Aug 2024 17:49:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: GCC Patches Cc: Vladimir Makarov , Richard Biener , Richard Sandiford , Jeff Law , Segher Boessenkool , Peter Bergner From: "Kewen.Lin" Subject: [PATCH/RFC] LRA: Don't emit move for substituted CONSTATNT_P operand [PR116170] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: -245uq6soI1AEsAmeQySAZIa7QwUlykd X-Proofpoint-GUID: Bpvx3odaKHSapHlB9loWDH5UyiRRdBb5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-09_06,2024-08-07_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 malwarescore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408090070 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, Commit r15-2084 exposes one ICE in LRA. Firstly, before r15-2084 KFmode has 126 bit precision while V1TImode has 128 bit precision, so the subreg (subreg:V1TI (reg:KF 131) 0) is paradoxical_subreg_p, which stops some passes from doing some optimization. After r15-2084, KFmode has the same mode precision as V1TImode, passes are able to optimize more, but it causes this ICE in LRA as described below: For insn 106 (set (mem:V1TI ...) (subreg:V1TI (reg:KF 133) 0)), which matches pattern (define_insn "*vsx_le_perm_store_" [(set (match_operand:VSX_LE_128 0 "memory_operand" "=Z,Q") (match_operand:VSX_LE_128 1 "vsx_register_operand" "+wa,r"))] "!BYTES_BIG_ENDIAN && TARGET_VSX && !TARGET_P9_VECTOR && !altivec_indexed_or_indirect_operand (operands[0], mode)" "@ # #" [(set_attr "type" "vecstore,store") (set_attr "length" "12,8") (set_attr "isa" ",*")]) LRA makes equivalence substitution on r133 with const double (const_double:KF 0.0), selects alternative 0 and fixes up operand 1 for constraint "wa", because operand 1 is OP_INOUT, so it considers assigning back to it as well, that is: lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg); But because old has been changed to const_double in equivalence substitution, the move is actually assigning to const_double, which is invalid and cause ICE. Considering reg:KF 133 is equivalent with (const_double:KF 0.0) even though this operand is OP_INOUT, IMHO there should not be any following uses of reg:KF 133, otherwise it doesn't have the chance to be equivalent to (const_double:KF 0.0). From this perspective, I think we can guard the lra_emit_move with nonimmediate_operand to exclude such case. Does it sound reasonable? btw, I also tried with disallowing equivalence substitution with CONSTANT_P value if the corresponding operand is OP_INOUT or OP_OUT, it can also fix this issue, but with more thinking it seems not necessary to stop such substitution if we can handle it later as above. Bootstrapped and regtested on x86_64-redhat-linux and powerpc64{,le}-linux-gnu. BR, Kewen ----- PR rtl-optimization/116170 gcc/ChangeLog: * lra-constraints.cc (curr_insn_transform): Don't emit move back to old operand if it's nonimmediate_operand. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr116170.c: New test. --- gcc/lra-constraints.cc | 3 ++- gcc/testsuite/gcc.target/powerpc/pr116170.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr116170.c -- 2.43.5 diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 92b343fa99a..024c85c87d9 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -4742,7 +4742,8 @@ curr_insn_transform (bool check_only_p) } *loc = new_reg; if (type != OP_IN - && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX) + && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX + && nonimmediate_operand (old, GET_MODE (old))) { start_sequence (); lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg); diff --git a/gcc/testsuite/gcc.target/powerpc/pr116170.c b/gcc/testsuite/gcc.target/powerpc/pr116170.c new file mode 100644 index 00000000000..6f6ca0f1ae9 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr116170.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ppc_float128_sw } */ +/* { dg-options "-mdejagnu-cpu=power8 -O2 -fstack-protector-strong -ffloat-store" } */ + +/* Verify there is no ICE. */ + +int a, d; +_Float128 b, c; +void +e () +{ + int f = 0; + if (a) + if (b || c) + f = 1; + if (d) + e (f ? 0 : b); +}