From patchwork Mon Nov 28 12:47:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 699959 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 3tS60Q3RDkz9vFb for ; Mon, 28 Nov 2016 23:47:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="La+do8Wx"; 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=JNH4cpSXBDCGho5N2F5VwOtKMs7E8Py+yS5AiEYGE09lh6PeJDZzA dBGfWF4k+KmxiZpFNmCwfys+TCNZ741C7S3cMs8Q5ccQkWJ8U61UFZ5KKsz7QYK8 MldkDquyjURdIKU0x7ZnzyGZc30s5pNMqRZ0wNAer2n+xefekV+3YU= 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=H6uFcZsOQzgQ1ZkNxHu5seM840Q=; b=La+do8WxLsTM7HDlXKJv yF2qQ7qbgszjrUKmZVPFfrv2AVkrmLXmSrch4wZZ66TncBk6W2Ho53XRoibVSh5+ cEa2T40izAGszOUDDX1ENhAvVuvWx3lxoNFymU1PpAMTXEPwBPAz2IqzspGa192N lumGW95axIOa8jGL5sCHqy8= Received: (qmail 3536 invoked by alias); 28 Nov 2016 12:47:41 -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 3525 invoked by uid 89); 28 Nov 2016 12:47:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=dispatch, simplification, tree-vrp.c, UD:tree-vrp.c 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; Mon, 28 Nov 2016 12:47:31 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 029F1AABE for ; Mon, 28 Nov 2016 12:47:29 +0000 (UTC) Date: Mon, 28 Nov 2016 13:47:28 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR78542 Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 The following fixes another issue with marrying the SSA propagator and match-and-simplify during propagation (which is tricky at best). Bootstrap and regtest running on x86_64-unknown-linux-gnu, I've applied the VRP patch below as well to see if the theory works out (VRP misses to handle simplifications to copies during propagation). I'm considering that change for and the fix for GCC 6 where the issue is latent. Richard. 2016-11-28 Richard Biener PR tree-optimization/78542 * tree-ssa-ccp.c (evaluate_stmt): Only valueize simplification if allowed. * gcc.dg/torture/pr78542.c: New testcase. Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 242913) +++ gcc/tree-ssa-ccp.c (working copy) @@ -1744,7 +1744,12 @@ evaluate_stmt (gimple *stmt) { fold_defer_overflow_warnings (); simplified = ccp_fold (stmt); - if (simplified && TREE_CODE (simplified) == SSA_NAME) + if (simplified + && TREE_CODE (simplified) == SSA_NAME + /* We may not use values of something that may be simulated again, + see valueize_op_1. */ + && (SSA_NAME_IS_DEFAULT_DEF (simplified) + || ! prop_simulate_again_p (SSA_NAME_DEF_STMT (simplified)))) { ccp_prop_value_t *val = get_value (simplified); if (val && val->lattice_val != VARYING) Index: gcc/testsuite/gcc.dg/torture/pr78542.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr78542.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr78542.c (revision 0) @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-additional-options "-w -Wno-psabi" } */ + +typedef unsigned V __attribute__ ((vector_size (16))); + +V +foo (unsigned x, V v) +{ + do { + v %= x; + x = 1; + } while (v[1]); + return v; +} + +int +main () +{ + V x = foo (5, (V) { 0, 1 }); + if (x[0] || x[1] || x[2] || x[3]) + __builtin_abort(); + return 0; +} 2016-11-28 Richard Biener * tree-vrp.c (vrp_visit_assignment_or_call): Handle simplifications to SSA names via extract_range_from_ssa_name if allowed. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 242913) +++ gcc/tree-vrp.c (working copy) @@ -7132,17 +7132,31 @@ vrp_visit_assignment_or_call (gimple *st && TYPE_MAX_VALUE (TREE_TYPE (lhs))) || POINTER_TYPE_P (TREE_TYPE (lhs)))) { + *output_p = lhs; + /* Try folding the statement to a constant first. */ tree tem = gimple_fold_stmt_to_constant_1 (stmt, vrp_valueize, vrp_valueize_1); - if (tem && is_gimple_min_invariant (tem)) - set_value_range_to_value (vr, tem, NULL); + if (tem) + { + if (TREE_CODE (tem) == SSA_NAME + && (SSA_NAME_IS_DEFAULT_DEF (tem) + || ! prop_simulate_again_p (SSA_NAME_DEF_STMT (tem)))) + { + extract_range_from_ssa_name (vr, tem); + return; + } + else if (is_gimple_min_invariant (tem)) + { + set_value_range_to_value (vr, tem, NULL); + return; + } + } /* Then dispatch to value-range extracting functions. */ - else if (code == GIMPLE_CALL) + if (code == GIMPLE_CALL) extract_range_basic (vr, stmt); else extract_range_from_assignment (vr, as_a (stmt)); - *output_p = lhs; } }