From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: text/plain 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 List-Id: 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) -- 2.25.1