From patchwork Thu Sep 7 08:46:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 810914 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-461664-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="T6vSgzzB"; 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 3xnvFY0Thjz9s8J for ; Thu, 7 Sep 2017 18:46:40 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=lzKFyAZ+GsyQXwxiPyBzVCcJhidnQ+6USBuJCtfp7YiG3EJZOhogf fy7zNiXQ6dWqI93Wafq9rZ1ePGpJjRQorUxvV8rMT9uR6HmcI13JFYyHijIM7ebN mezgTZANDx4IC+ZlTE/xbMiRucsETZaftTUuU/28HLRtkoUWWmJJK8= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=3q/TUfUT2inR23grTNL/HXmOSD4=; b=T6vSgzzBDfHeDSrz6g+V npqrEKSf1tHknNse5t9Uo2ZPgMJuNP1Qy/XCzQoMR/xmp2yW1BHlXASuaF03oBWK gFykXH7NJgR0DUiWiVkaIDT31FP+qoQ5MyiIOlCCKSozTgjYIjoZMCMeNM6VKxdr 4Y3I2y7tQVCv4sjlf6eIK/k= Received: (qmail 49463 invoked by alias); 7 Sep 2017 08:46:30 -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 48918 invoked by uid 89); 7 Sep 2017 08:46:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=equation, forwarders X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Sep 2017 08:46:27 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 10979AD57 for ; Thu, 7 Sep 2017 08:46:25 +0000 (UTC) Date: Thu, 7 Sep 2017 10:46:24 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Enhance PHI processing in VN Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This enhances VN to do the same PHI handling as CCP, meeting undefined and constant to constant. I've gone a little bit further (and maybe will revisit this again) in also meeting all-undefined to undefined taking one of the undefined args as the value number. I feel like this might run into the equation issues I mentioned in the other mail so it would be cleaner to invent a "new" undefined value number here -- but I have to make sure to not create too many default-defs or break iteration convergence (default defs are also expensive given they require a decl - sth I want to change as well). So for now I guess I'll stick with the slightly bogus(?) way also hoping for a testcase that shows the issue this uncovers. Note it's required to handle _3 = PHI <_1(D), _2(D)> .. _4 = PHI <_3, 1> consistently with _4 = PHI <_1(D), _2(D), 1> aka with/without extra forwarders. Similar to CCP/copyprop this doesn't allow copies to be propagated this way as this removes most gcc.dg/Wuninitialized* warnings we test for... Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2017-09-07 Richard Biener * tree-ssa-sccnv.c (visit_phi): Handle meeting undefined values. * gcc.dg/tree-ssa/ssa-fre-59.c: New testcase. Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-59.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-59.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-59.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-fre1" } */ + +int i; +int foo (int b) +{ + int j; + i = 1; + if (b) + j = i; + return i - j; +} + +/* { dg-final { scan-tree-dump "return 0;" "fre1" } } */ Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 251833) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -3864,6 +3864,7 @@ visit_phi (gimple *phi) tree result; tree sameval = VN_TOP; bool allsame = true; + tree seen_undef = NULL_TREE; unsigned n_executable = 0; /* TODO: We could check for this in init_sccvn, and replace this @@ -3884,8 +3885,12 @@ visit_phi (gimple *phi) if (TREE_CODE (def) == SSA_NAME) def = SSA_VAL (def); if (def == VN_TOP) - continue; - if (sameval == VN_TOP) + ; + /* Ignore undefined defs here. */ + else if (TREE_CODE (def) == SSA_NAME + && ssa_undefined_value_p (def, false)) + seen_undef = def; + else if (sameval == VN_TOP) sameval = def; else if (!expressions_equal_p (def, sameval)) { @@ -3893,7 +3898,18 @@ visit_phi (gimple *phi) break; } } - + /* If we found undefined values and didn't end up with a constant + drop back to varying as otherwise we end up removing most late + uninitialized use warnings. CCP/copyprop have the same restriction. */ + if (allsame && seen_undef) + { + /* Unless this was the only value we've seen. */ + if (sameval == VN_TOP) + sameval = seen_undef; + else if (! is_gimple_min_invariant (sameval)) + allsame = false; + } + /* If none of the edges was executable or all incoming values are undefined keep the value-number at VN_TOP. If only a single edge is exectuable use its value. */