From patchwork Mon Oct 23 10:57:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 829229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464720-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uV0tl6AH"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yLCzp1szdz9t7X for ; Mon, 23 Oct 2017 21:57:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=PymDJSr9bzEuvvPz w8862qlJcqcHV/Ow5g5EQLRrLpsUuOMAxtXEACgvFu9Dnw/+q4RBq5lexhAnjmzC QRgbjG2nmWi96nvg3ON1DsvYTFKxgmWVQ2Ljr/6e4dijvU5ywxv/hRxxwoVnWHIe SmdTk8ld4tTSTyaMFUfHZsB/OK0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=V/Cu4LhTdWRYKpetSef2wE O8+cQ=; b=uV0tl6AHTRXzWFrnGq1f43DOo9FVugS6cBBkHrbykZQc/HVCBAQCHe z4vktFpUeliTGr+fdyWQtE5eHYAqEBqMRN2Nsdq3LHz9USXbb9BQ/7V7Av8Xho5h 1Dg0agODr3Ox/xlUFpM0SZUfcEHYP5yaA6l1FfrkqGavUntkhjF8k= Received: (qmail 81677 invoked by alias); 23 Oct 2017 10:57:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 81662 invoked by uid 89); 23 Oct 2017 10:57:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-8.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_BRBL_LASTEXT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=fulfill, PART, power6 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 10:57:47 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 1E9F581C18 for ; Mon, 23 Oct 2017 12:57:45 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J3Q2gtyOboyR for ; Mon, 23 Oct 2017 12:57:45 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id E79A88138E for ; Mon, 23 Oct 2017 12:57:44 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR middle-end/82569 Date: Mon, 23 Oct 2017 12:57:44 +0200 Message-ID: <6561954.cUVdaKEquF@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Hi, this is the regression present on the mainline for Power6 and introduced by my patch fiddling with SUBREG_PROMOTED_VAR_P in expand_expr_real_1. It turns out that the ouf-of-ssa pass implicitly assumes that promoted RTXes for partitions are fully initialized (because it can generate direct moves in promoted mode) and clearing SUBREG_PROMOTED_VAR_P for some of them goes against this. Therefore the attached patch goes in the opposite direction and initializes the RTXes for problematic partitions on function entry. Surprisingly enough, this generates smaller code on average at -O2 for gcc.c-torture/compile: 49 files changed, 1243 insertions(+), 1694 deletions(-) probably because the compiler can now infer values on paths from entry where variables are uninitialized. Tested on PowerPC64/Linux, OK for the mainline? 2017-10-23 Eric Botcazou PR middle-end/82569 * tree-outof-ssa.h (always_initialized_rtx_for_ssa_name_p): Delete. * expr.c (expand_expr_real_1) : Revert latest change. * loop-iv.c (iv_get_reaching_def): Likewise. * cfgexpand.c (expand_one_ssa_partition): Initialize the RTX if the variable is promoted and the partition contains undefined values. Index: cfgexpand.c =================================================================== --- cfgexpand.c (revision 253968) +++ cfgexpand.c (working copy) @@ -1391,10 +1391,18 @@ expand_one_ssa_partition (tree var) } machine_mode reg_mode = promote_ssa_mode (var, NULL); - rtx x = gen_reg_rtx (reg_mode); set_rtl (var, x); + + /* For a promoted variable, X will not be used directly but wrapped in a + SUBREG with SUBREG_PROMOTED_VAR_P set, which means that the RTL land + will assume that its upper bits can be inferred from its lower bits. + Therefore, if X isn't initialized on every path from the entry, then + we must do it manually in order to fulfill the above assumption. */ + if (reg_mode != TYPE_MODE (TREE_TYPE (var)) + && bitmap_bit_p (SA.partitions_for_undefined_values, part)) + emit_move_insn (x, CONST0_RTX (reg_mode)); } /* Record the association between the RTL generated for partition PART Index: expr.c =================================================================== --- expr.c (revision 253968) +++ expr.c (working copy) @@ -9912,43 +9912,24 @@ expand_expr_real_1 (tree exp, rtx target && GET_MODE (decl_rtl) != dmode) { machine_mode pmode; - bool always_initialized_rtx; /* Get the signedness to be used for this variable. Ensure we get the same mode we got when the variable was declared. */ if (code != SSA_NAME) - { - pmode = promote_decl_mode (exp, &unsignedp); - always_initialized_rtx = true; - } + pmode = promote_decl_mode (exp, &unsignedp); else if ((g = SSA_NAME_DEF_STMT (ssa_name)) && gimple_code (g) == GIMPLE_CALL && !gimple_call_internal_p (g)) - { - pmode = promote_function_mode (type, mode, &unsignedp, - gimple_call_fntype (g), 2); - always_initialized_rtx - = always_initialized_rtx_for_ssa_name_p (ssa_name); - } + pmode = promote_function_mode (type, mode, &unsignedp, + gimple_call_fntype (g), + 2); else - { - pmode = promote_ssa_mode (ssa_name, &unsignedp); - always_initialized_rtx - = always_initialized_rtx_for_ssa_name_p (ssa_name); - } - + pmode = promote_ssa_mode (ssa_name, &unsignedp); gcc_assert (GET_MODE (decl_rtl) == pmode); temp = gen_lowpart_SUBREG (mode, decl_rtl); - - /* We cannot assume anything about an existing extension if the - register may contain uninitialized bits. */ - if (always_initialized_rtx) - { - SUBREG_PROMOTED_VAR_P (temp) = 1; - SUBREG_PROMOTED_SET (temp, unsignedp); - } - + SUBREG_PROMOTED_VAR_P (temp) = 1; + SUBREG_PROMOTED_SET (temp, unsignedp); return temp; } Index: loop-iv.c =================================================================== --- loop-iv.c (revision 253968) +++ loop-iv.c (working copy) @@ -353,7 +353,7 @@ iv_get_reaching_def (rtx_insn *insn, rtx adef = DF_REF_CHAIN (use)->ref; /* We do not handle setting only part of the register. */ - if (DF_REF_FLAGS (adef) & (DF_REF_READ_WRITE | DF_REF_SUBREG)) + if (DF_REF_FLAGS (adef) & DF_REF_READ_WRITE) return GRD_INVALID; def_insn = DF_REF_INSN (adef); Index: tree-outof-ssa.h =================================================================== --- tree-outof-ssa.h (revision 253968) +++ tree-outof-ssa.h (working copy) @@ -74,18 +74,6 @@ get_gimple_for_ssa_name (tree exp) return NULL; } -/* Return whether the RTX expression representing the storage of the outof-SSA - partition that the SSA name EXP is a member of is always initialized. */ -static inline bool -always_initialized_rtx_for_ssa_name_p (tree exp) -{ - int p = partition_find (SA.map->var_partition, SSA_NAME_VERSION (exp)); - if (SA.map->partition_to_view) - p = SA.map->partition_to_view[p]; - gcc_assert (p != NO_PARTITION); - return !bitmap_bit_p (SA.partitions_for_undefined_values, p); -} - extern bool ssa_is_replaceable_p (gimple *stmt); extern void finish_out_of_ssa (struct ssaexpand *sa); extern unsigned int rewrite_out_of_ssa (struct ssaexpand *sa);