From patchwork Fri Oct 21 12:11:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 685072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3t0l0p0R4vz9sCg for ; Fri, 21 Oct 2016 23:12:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LdeKxk39; dkim-atps=neutral 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=cEDBvGje9nFS9REbwnyaMY1g12Btc7KCNAlYd1UNF6WCQZNABkmel BZEBv6i37X0zqubOp2f9cxkefBMG1ZvqfRbFOT+YqJ+4vywPxQvtE++Nah1CLNNJ kQy5WEc/T4HLIYjtlQxtS3HyiKCFbhMBHTA2ZAxgrtcWh3yQYLrSAA= 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=jOlxgqcItnfEgYWfK0conz30TC4=; b=LdeKxk39yZicbWMAqbiB 2qGbJ/yoOdGbOyYMNdRhzZPV6L59Vpio/H/9icAltqFYRdQ2dQLSMt4+RUUZUJT2 jsZZRsjpqD7KRKTECkEc2K62//VBccM/Rn8J8E7l6i2YT7x5M1mYL7u9WoT7sVLW BWJ2A6hooX78h6rZKvjWPJ0= Received: (qmail 30780 invoked by alias); 21 Oct 2016 12:11:45 -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 30756 invoked by uid 89); 21 Oct 2016 12:11:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.5 required=5.0 tests=BAYES_50, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=recording, forwarders, edge_iterator, sk:EDGE_FA X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Oct 2016 12:11:34 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D9152ABC8 for ; Fri, 21 Oct 2016 12:11:30 +0000 (UTC) Date: Fri, 21 Oct 2016 14:11:29 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Use SCEV in EVRP, fix single predecessor discovery Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 This makes us derive ranges for loop IVs in EVRP using adjust_range_with_scevs. It also allows us to derive ranges from conditions in loop preheaders (I think that's still broken because we force simple preheaders and predecessor search doesn't follow forwarders -- sth for a followup). Bootstrap and regtest running on x86_64-unknown-linux-gnu. Richard. 2016-10-21 Richard Biener * tree-vrp.c (evrp_dom_walker::before_dom_children): Ignore backedges when identifying the single predecessor to take conditional info from. Use SCEV to get at ranges for loop IVs. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 241400) +++ gcc/tree-vrp.c (working copy) @@ -10693,12 +10693,29 @@ edge evrp_dom_walker::before_dom_children (basic_block bb) { tree op0 = NULL_TREE; + edge_iterator ei; + edge e; push_value_range (NULL_TREE, NULL); - if (single_pred_p (bb)) + + edge pred_e = NULL; + FOR_EACH_EDGE (e, ei, bb->preds) + { + /* Ignore simple backedges from this to allow recording conditions + in loop headers. */ + if (dominated_by_p (CDI_DOMINATORS, e->src, e->dest)) + continue; + if (! pred_e) + pred_e = e; + else + { + pred_e = NULL; + break; + } + } + if (pred_e) { - edge e = single_pred_edge (bb); - gimple *stmt = last_stmt (e->src); + gimple *stmt = last_stmt (pred_e->src); if (stmt && gimple_code (stmt) == GIMPLE_COND && (op0 = gimple_cond_lhs (stmt)) @@ -10715,7 +10732,7 @@ evrp_dom_walker::before_dom_children (ba op1 = drop_tree_overflow (op1); /* If condition is false, invert the cond. */ - if (e->flags & EDGE_FALSE_VALUE) + if (pred_e->flags & EDGE_FALSE_VALUE) code = invert_tree_comparison (gimple_cond_code (stmt), HONOR_NANS (op0)); /* Add VR when (OP0 CODE OP1) condition is true. */ @@ -10743,11 +10760,7 @@ evrp_dom_walker::before_dom_children (ba } /* Visit PHI stmts and discover any new VRs possible. */ - gimple_stmt_iterator gsi; - edge e; - edge_iterator ei; bool has_unvisited_preds = false; - FOR_EACH_EDGE (e, ei, bb->preds) if (e->flags & EDGE_EXECUTABLE && !(e->src->flags & BB_VISITED)) @@ -10761,12 +10774,24 @@ evrp_dom_walker::before_dom_children (ba { gphi *phi = gpi.phi (); tree lhs = PHI_RESULT (phi); + if (virtual_operand_p (lhs)) + continue; value_range vr_result = VR_INITIALIZER; if (!has_unvisited_preds && stmt_interesting_for_vrp (phi)) extract_range_from_phi_node (phi, &vr_result); else - set_value_range_to_varying (&vr_result); + { + /* When we have an unvisited executable predecessor we can't + use PHI arg ranges which may be still UNDEFINED but have + to use VARYING for them. But we can still resort to + SCEV for loop header PHIs. */ + set_value_range_to_varying (&vr_result); + struct loop *l; + if ((l = loop_containing_stmt (phi)) + && l->header == gimple_bb (phi)) + adjust_range_with_scev (&vr_result, l, phi, lhs); + } update_value_range (lhs, &vr_result); /* Mark PHIs whose lhs we fully propagate for removal. */ @@ -10778,7 +10803,8 @@ evrp_dom_walker::before_dom_children (ba edge taken_edge = NULL; /* Visit all other stmts and discover any new VRs possible. */ - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); + !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); tree output = NULL_TREE;