From patchwork Wed Nov 21 02:28:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1000844 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-490599-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Euzu/IrX"; 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 43062M5lJcz9sB7 for ; Wed, 21 Nov 2018 13:28:40 +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:message-id:date:mime-version:content-type; q=dns; s= default; b=mqK59ooCyOBIdxzSPTvVHYgysTIhKrA84fu/PSBuCADQ+DxSqC5Ok lIdxfQ7c3DCNnPBjjfMSL701vF5yGtnWL3TFKOixWTfskgsmqw/lhU5rTjndMtwX CguOJvHhAoOXNUt296kK2HnTTK0zVUlgtcKHB47dqvzphEFsGTwpLY= 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:message-id:date:mime-version:content-type; s= default; bh=dGGkR8jBIPlORiV1PezhuXf148k=; b=Euzu/IrXKiHBqUU5U1C3 gVDvO/D9a0NVRMdQWzWswr+0bx8g0JyGXwHtW4mSCUGv1M4/Gl6K+Qp9HXkaVJLM II+Tu8oXXDYqnV454eHaLxfHSLBMx8DV/DetUvw7mMMvo5SYblHrNSy1sxtvnoZW v/YxMvyWu8CqanDqyDyCdPA= Received: (qmail 51181 invoked by alias); 21 Nov 2018 02:28:33 -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 51166 invoked by uid 89); 21 Nov 2018 02:28:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Nov 2018 02:28:31 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E11853082A31 for ; Wed, 21 Nov 2018 02:28:29 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-27.rdu2.redhat.com [10.10.112.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B6C75885A for ; Wed, 21 Nov 2018 02:28:28 +0000 (UTC) From: Jeff Law Openpgp: preference=signencrypt To: gcc-patches Subject: Fix regression introduced by 88069 Message-ID: <0cee3370-f035-7e8c-6c6f-f77153a40c0e@redhat.com> Date: Tue, 20 Nov 2018 19:28:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Richi's recent change to fix 88069 is causing various targets to fail tree-ssa/20030711-2.c. That test is verifying a variety of optimizations occur during the first DOM pass. Prior to Richi's change FRE1 would do some significant cleanups of the IL and as a result DOM was fully able to optimize the resultant code. After Richi's change we've got a redundant load in the IL. After analyzing the CFG and IL it was clear that DOM *should* be able to remove the redundant load, but simply wasn't. DOM would discover that it could statically determine the result of a branch condition. This resulted in one arm of the branch becoming unreachable. That in turn caused some PHI nodes to become degenerates. Normally when a PHI node becomes a degenerate we record it as a copy in the const_and_copies table and *most* of the time we'll propagate the src value into uses of the dest. But propagation is not guaranteed (there's a BZ around that issue you can find if you dig into the history of some of this code). Anyway, exposing the degenerate PHI *should* have exposed the redundant load, but we didn't record anything into the const/copies table for the virtual phi. That's a conscious decision to avoid issues with overlapping lifetimes of virtual SSA_NAMEs. While investigating the history here I noticed Richi's little trick which allows propagation of virtuals if we propagate to all the uses. Twiddling DOM to use that same trick results in the virtual operand propagating. That in turn allows DOM to see and remove the redundant load. Bootstrapped and regression tested on x86_64 where is fixes 20030711-2.c. Also verified that it fixed various other targets where that test had started failing. Installing on the trunk. jeff commit 1438e5e18df9f927990074dd32572abf924eba86 Author: Jeff Law Date: Tue Nov 20 18:10:28 2018 -0700 2018-11-20 Jeff Law PR tree-optimization/88069 * tree-ssa-dom.c (record_equivalences_from_phis): Propagate away degenerate virtual PHIs. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aece55980f0..5c7a9509b35 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-11-20 Jeff Law + + PR tree-optimization/88069 + * tree-ssa-dom.c (record_equivalences_from_phis): Propagate away + degenerate virtual PHIs. + 2018-11-20 Jakub Jelinek PR tree-optimization/87895 diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 7787da8b237..ce840488403 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1106,10 +1106,13 @@ record_equivalences_from_phis (basic_block bb) { gphi_iterator gsi; - for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); ) { gphi *phi = gsi.phi (); + /* We might eliminate the PHI, so advance GSI now. */ + gsi_next (&gsi); + tree lhs = gimple_phi_result (phi); tree rhs = NULL; size_t i; @@ -1159,9 +1162,26 @@ record_equivalences_from_phis (basic_block bb) this, since this is a true assignment and not an equivalence inferred from a comparison. All uses of this ssa name are dominated by this assignment, so unwinding just costs time and space. */ - if (i == gimple_phi_num_args (phi) - && may_propagate_copy (lhs, rhs)) - set_ssa_name_value (lhs, rhs); + if (i == gimple_phi_num_args (phi)) + { + if (may_propagate_copy (lhs, rhs)) + set_ssa_name_value (lhs, rhs); + else if (virtual_operand_p (lhs)) + { + gimple *use_stmt; + imm_use_iterator iter; + use_operand_p use_p; + /* For virtual operands we have to propagate into all uses as + otherwise we will create overlapping life-ranges. */ + FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs) + FOR_EACH_IMM_USE_ON_STMT (use_p, iter) + SET_USE (use_p, rhs); + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs)) + SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs) = 1; + gimple_stmt_iterator tmp_gsi = gsi_for_stmt (phi); + remove_phi_node (&tmp_gsi, true); + } + } } }