From patchwork Thu Jul 30 09:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1338729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BHQJb3tcbz9sRX for ; Thu, 30 Jul 2020 19:35:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F4243861851; Thu, 30 Jul 2020 09:35:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 4AE2B3857C41 for ; Thu, 30 Jul 2020 09:35:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4AE2B3857C41 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 9D2FDAF8A for ; Thu, 30 Jul 2020 09:36:02 +0000 (UTC) Date: Thu, 30 Jul 2020 11:35:50 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/96370 - make reassoc expr rewrite more robust Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In the face of the more complex tricks in reassoc with respect to negate processing it can happen that the expression rewrite is fooled to recurse on a leaf and pick up a bogus expression code. The following patch makes the expression rewrite more robust in providing the expression code to it directly since it is the same for all operations in a chain. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to master. 2020-07-30 Richard Biener PR tree-optimization/96370 * tree-ssa-reassoc.c (rewrite_expr_tree): Add operation code parameter and use it instead of picking it up from the stmt that is being rewritten. (reassociate_bb): Pass down the operation code. * gcc.dg/pr96370.c: New testcase. --- gcc/testsuite/gcc.dg/pr96370.c | 8 ++++++++ gcc/tree-ssa-reassoc.c | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr96370.c diff --git a/gcc/testsuite/gcc.dg/pr96370.c b/gcc/testsuite/gcc.dg/pr96370.c new file mode 100644 index 00000000000..b939b2141d6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96370.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target dfp } } */ +/* { dg-options "-O2 -ffast-math" } */ + +void c(_Decimal128); +void a(_Decimal128 b) +{ + c(-b * b); +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index d06b693ec76..266cff376e5 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -4913,7 +4913,7 @@ insert_stmt_before_use (gimple *stmt, gimple *stmt_to_insert) recursive invocations. */ static tree -rewrite_expr_tree (gimple *stmt, unsigned int opindex, +rewrite_expr_tree (gimple *stmt, enum tree_code rhs_code, unsigned int opindex, vec ops, bool changed, bool next_changed) { tree rhs1 = gimple_assign_rhs1 (stmt); @@ -4960,7 +4960,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, = find_insert_point (stmt, oe1->op, oe2->op); lhs = make_ssa_name (TREE_TYPE (lhs)); stmt - = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt), + = gimple_build_assign (lhs, rhs_code, oe1->op, oe2->op); gimple_set_uid (stmt, uid); gimple_set_visited (stmt, true); @@ -5004,7 +5004,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, /* Recurse on the LHS of the binary operator, which is guaranteed to be the non-leaf side. */ tree new_rhs1 - = rewrite_expr_tree (SSA_NAME_DEF_STMT (rhs1), opindex + 1, ops, + = rewrite_expr_tree (SSA_NAME_DEF_STMT (rhs1), rhs_code, opindex + 1, ops, changed || oe->op != rhs2 || next_changed, false); @@ -5030,7 +5030,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex, gimple *insert_point = find_insert_point (stmt, new_rhs1, oe->op); lhs = make_ssa_name (TREE_TYPE (lhs)); - stmt = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt), + stmt = gimple_build_assign (lhs, rhs_code, new_rhs1, oe->op); gimple_set_uid (stmt, uid); gimple_set_visited (stmt, true); @@ -6477,7 +6477,7 @@ reassociate_bb (basic_block bb) if (len >= 3) swap_ops_for_binary_stmt (ops, len - 3, stmt); - new_lhs = rewrite_expr_tree (stmt, 0, ops, + new_lhs = rewrite_expr_tree (stmt, rhs_code, 0, ops, powi_result != NULL || negate_result, len != orig_len);