From patchwork Tue Oct 24 10:15:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 157365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1838454vqx; Tue, 24 Oct 2023 03:15:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFsxSjBQGpL1B/XLYdDc/0Dh/3br8Z6/lEcauE7bSpiXlQV68FRmFd5huLNqVwSb3C2pYf X-Received: by 2002:a05:6808:1a23:b0:3ae:349:7c03 with SMTP id bk35-20020a0568081a2300b003ae03497c03mr15819920oib.27.1698142540815; Tue, 24 Oct 2023 03:15:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698142540; cv=pass; d=google.com; s=arc-20160816; b=bn3OW5/gRkonDEiyLwBO71IzelSX5mae3NJdS1umlggRFaqy0jDdaKYKo4/83d415L 0Rw2zaQj628bYvFudJ6OA9qys6wDFfSE/sRoVAH1meNlftZxTVbNB1FKuKPKlLQSTmbJ 5lQM15+Uu3VSj2/7IDDY0jsqxYRH8RsAvP7xviMjwC6Ry3fFZMQGATzRuRtnkhFTzGLr n+c6fm3q86+Rj/uQAZU0DixIYHakXIhjG8flS2HObyf7KQevpuz2qo1qcEOeKKRjBRkq m1KsZp+dj+Nzh2i9yrfl6n0zyYF658xitAXa2YyieyurpF/3RjHs/wIjIsVN5jC4fUDt dgIA== 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:mime-version:user-agent :message-id:date:subject:cc:mail-followup-to:to:from:arc-filter :dmarc-filter:delivered-to; bh=Yfaq5fmx6Ry7x4/zboF08PGxEHNkahc4z0ehPhlq8Ig=; fh=+zKahnQ9dI9rCMQA/vTUSn1PPyLwgfSULGOjxoIZkos=; b=xSORc1eDhNyCYLkrLbuy7d0aEqkAtv7sVnwaHuyAgkKrGHBWS0GLZk2xtq1ekZzTpE q8Jr1IxuCMk/p/JvcRulHXxboImt+krfqVEoOD9y0+YHb0J/u1npLUvUG4fY2/iFzew/ i3Wd9ljRIEtBCc5TL6HcL3XY3/GIvf+e4mYTQwaj0+xSGUY84bHGRCA2u6uNPb/gMk7Q wZuDcXOB8zgOtd+oXOaKRNoEl1aCDUek26bx5PGjRQWvSCfPYSQQjAqH/YLmiVSr3Bjc 7enkxlza71MEjHKia1c3siJr2Np/Kp259WrVzub7nUn6N0MjK3vofk7+cvfF7scdwvrg SBGQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fe19-20020a0562140b9300b0064188f9b3d0si6850624qvb.188.2023.10.24.03.15.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:15:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 935E53858421 for ; Tue, 24 Oct 2023 10:15:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id F2F803858D37 for ; Tue, 24 Oct 2023 10:15:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F2F803858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F2F803858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698142519; cv=none; b=aCh9Wy4P7iatmt60gQeaq/3Vvxk8VMg/AuGC3DsY9DAEcWWjJle81rZizXY57IYBy1NMWDnhPHouqxzMQG3JIPJtdGpSROZGilusLcdLvws1WO3WkLruj0NXb3xk+vUAizheHIIqZJH4mhydpYjl3SG6Dnr7PFpmX8mw58ja/BI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698142519; c=relaxed/simple; bh=XyWviFI274zl+nmVQXwedvbJaxxXOBJjyLpU//d5OEw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xNB87CfCN5UXsQhyj0f1A1wSFMpQj8SdkzxqrrcGKeb1nvsTepjKE6Cly6eenTr+fvkRUb0Qsy6kLHxO5EEm3oBIi4c8vo4qOkmi8xDgNsXEra7KHyMwYgI5085/fxPhHifb+xtWcapo5BqcKmRH0vMrj4FZxIk/UvjQgqg5ayY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A7EB42F4; Tue, 24 Oct 2023 03:15:58 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 38EC73F64C; Tue, 24 Oct 2023 03:15:17 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, jlaw@ventanamicro.com, richard.sandiford@arm.com Cc: jlaw@ventanamicro.com Subject: [PATCH] recog: Fix propagation into ASM_OPERANDS Date: Tue, 24 Oct 2023 11:15:16 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-23.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780631512653654043 X-GMAIL-MSGID: 1780631512653654043 An inline asm with multiple output operands is represented as a parallel set in which the SET_SRCs are the same (shared) ASM_OPERANDS. insn_propgation didn't account for this, and instead propagated into each ASM_OPERANDS individually. This meant that it could apply a substitution X->Y to Y itself, which (a) could create circularity and (b) would be semantically wrong in any case, since Y might use a different value of X. This patch checks explicitly for parallels involving ASM_OPERANDS, just like combine does. Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install? Richard gcc/ * recog.cc (insn_propagation::apply_to_pattern_1): Handle shared ASM_OPERANDS. --- gcc/recog.cc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/gcc/recog.cc b/gcc/recog.cc index e12b4c9500e..3bd2d73c259 100644 --- a/gcc/recog.cc +++ b/gcc/recog.cc @@ -1339,13 +1339,26 @@ insn_propagation::apply_to_pattern_1 (rtx *loc) && apply_to_pattern_1 (&COND_EXEC_CODE (body))); case PARALLEL: - { - int last = XVECLEN (body, 0) - 1; - for (int i = 0; i < last; ++i) - if (!apply_to_pattern_1 (&XVECEXP (body, 0, i))) - return false; - return apply_to_pattern_1 (&XVECEXP (body, 0, last)); - } + for (int i = 0; i < XVECLEN (body, 0); ++i) + { + rtx *subloc = &XVECEXP (body, 0, i); + if (GET_CODE (*subloc) == SET) + { + if (!apply_to_lvalue_1 (SET_DEST (*subloc))) + return false; + /* ASM_OPERANDS are shared between SETs in the same PARALLEL. + Only process them on the first iteration. */ + if ((i == 0 || GET_CODE (SET_SRC (*subloc)) != ASM_OPERANDS) + && !apply_to_rvalue_1 (&SET_SRC (*subloc))) + return false; + } + else + { + if (!apply_to_pattern_1 (subloc)) + return false; + } + } + return true; case ASM_OPERANDS: for (int i = 0, len = ASM_OPERANDS_INPUT_LENGTH (body); i < len; ++i)