From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D1C5C394FC38 for ; Tue, 4 May 2021 10:31:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D1C5C394FC38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A2D06B2E4 for ; Tue, 4 May 2021 10:31:30 +0000 (UTC) Date: Tue, 4 May 2021 12:31:29 +0200 (CEST) From: Richard Biener Sender: rguenther@ryzen.fritz.box To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100329 - avoid reassociating asm goto defs Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 May 2021 10:31:33 -0000 This avoids reassociating asm goto defs because we have no idea on which outgoing edge to insert defs. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-05-04 Richard Biener PR tree-optimization/100329 * tree-ssa-reassoc.c (can_reassociate_p): Do not reassociate asm goto defs. (insert_stmt_after): Assert we're not running into asm goto. * gcc.dg/torture/pr100329.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr100329.c | 16 ++++++++++++++++ gcc/tree-ssa-reassoc.c | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr100329.c diff --git a/gcc/testsuite/gcc.dg/torture/pr100329.c b/gcc/testsuite/gcc.dg/torture/pr100329.c new file mode 100644 index 00000000000..b90700dd5f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr100329.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-additional-options "--param tree-reassoc-width=2" } */ + +unsigned int a0; + +unsigned int +foo (unsigned int a1, unsigned int a2) +{ + unsigned int x; + + asm goto ("" : "=r" (x) : : : lab); + a0 = x; + + lab: + return x + a1 + a2 + 1; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 8e2a4896d14..359367c9382 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -1446,6 +1446,10 @@ insert_stmt_after (gimple *stmt, gimple *insert_point) gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); return; } + else if (gimple_code (insert_point) == GIMPLE_ASM) + /* We have no idea where to insert - it depends on where the + uses will be placed. */ + gcc_unreachable (); else /* We assume INSERT_POINT is a SSA_NAME_DEF_STMT of some SSA_NAME, thus if it must end a basic block, it should be a call that can @@ -5893,6 +5897,12 @@ can_reassociate_p (tree op) tree type = TREE_TYPE (op); if (TREE_CODE (op) == SSA_NAME && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op)) return false; + /* Make sure asm goto outputs do not participate in reassociation since + we have no way to find an insertion place after asm goto. */ + if (TREE_CODE (op) == SSA_NAME + && gimple_code (SSA_NAME_DEF_STMT (op)) == GIMPLE_ASM + && gimple_asm_nlabels (as_a (SSA_NAME_DEF_STMT (op))) != 0) + return false; if ((ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)) || NON_SAT_FIXED_POINT_TYPE_P (type) || (flag_associative_math && FLOAT_TYPE_P (type))) -- 2.26.2