From patchwork Fri Aug 19 23:25:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 661047 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 3sGJxn0YCCz9sXR for ; Sat, 20 Aug 2016 09:26:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=L+SmCHwU; 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:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=hQLQBdJ4DX79+Z4c 9G8HHziKVzbd9q516GTwpWmLKZ9r+rdHNNt3U7FIc6MGgw+a3tYYo/932Mfh71Fg aheXNpCxbPlk3+8eUL+XBoHZzALM9BL9VPM8n8wK0zD3B3/B5Hdpq42invYs0tKo aawX3SjUO0eq47XC+6EGhj5qQyI= 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 :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=B8aZ5H7rWkVIqOENE5iTq0 wSBU8=; b=L+SmCHwUBc1SGzC729yalNXpcRCYHba0rHcmEXsahcercn44jFYarA ybR8qwIPnpG9+ZkTqGRH7dXOgHOtmcgEI5WB0Roj5k5qpF9V8IJhhH9djdaaCEVc 88qaZUObDZVWQu/HRiKc4Q+kak1RNNKfdIZnx0I5T/+9fcXImmVvg= Received: (qmail 84014 invoked by alias); 19 Aug 2016 23:26:11 -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 83997 invoked by uid 89); 19 Aug 2016 23:26:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=XALLOCAVEC, xallocavec, sk:vector_, sk:VECTOR_ X-HELO: mail-qk0-f194.google.com Received: from mail-qk0-f194.google.com (HELO mail-qk0-f194.google.com) (209.85.220.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Aug 2016 23:26:00 +0000 Received: by mail-qk0-f194.google.com with SMTP id o1so5164760qkd.2 for ; Fri, 19 Aug 2016 16:26:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=9Rfj8FS+wrKKyBnQ8ZtY9JuGLpsGSihOXYZutMwN+Jc=; b=EKFEu43/V6ea128P7WLfI29jcPme6LRv/LIWg4xFPOceTfKj1+hrGU6dOmv1QW8wrv rpZGf6ZDwPIi4ppy9U3BCJRViplUkDPLqTF2WqbMP+fB5RMv/Km0bOvCwq0uIDjfSGkd 3WuoX/YtuW2fCuGdFBGyLMD4rqhaOJlhFdbuaYPyRa9mXCIRQLN+CvqJAuWVOE+zCrEe yWJEHH4s0rBz2pbjRnwdAajFZBVbEjhIANlZs0qPz+H3ap3AM8L1Hg1igWg4yNeWyFgN MRJy9DnfQBlphd1bQBqaSLzAWI2cUk3k/4wjLg9HHVR2XsgEfSpP97QGlhrCjEXk7OIk erQg== X-Gm-Message-State: AE9vXwOshsl/6XdoFQNA08O0TBjdkX/3E7itK8YtUxQWroO8iWCDygh5lq+UoAXOMN19Rg== X-Received: by 10.55.176.65 with SMTP id z62mr11962539qke.0.1471649158609; Fri, 19 Aug 2016 16:25:58 -0700 (PDT) Received: from [192.168.1.130] (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id j67sm5049665qkf.41.2016.08.19.16.25.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Aug 2016 16:25:57 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 19 Aug 2016 19:25:57 -0400 (EDT) To: Yuri Rumyantsev cc: Richard Biener , Patrick Palka , GCC Patches Subject: Re: [PATCH] Restrict jump threading statement simplifier to scalar types (PR71077) In-Reply-To: Message-ID: References: <20160818182518.7397-1-patrick@parcs.ath.cx> User-Agent: Alpine 2.20.13 (DEB 116 2015-12-14) MIME-Version: 1.0 On Fri, 19 Aug 2016, Yuri Rumyantsev wrote: > Hi, > > Here is a simple test-case to reproduce 176.gcc failure (I run it on > Haswell machine). > Using 20160819 compiler build we get: > gcc -O3 -m32 -mavx2 test.c -o test.ref.exe > /users/ysrumyan/isse_6866$ ./test.ref.exe > Aborted (core dumped) > > If I apply patch proposed by Patrick test runs properly > Instead of running we can check number of .jump thread. Thanks! With this test case I was able to identify the cause of the wrong code generation. Turns out that the problem lies in fold-const.c. It does not correctly fold VECTOR_CST comparisons that have a scalar boolean result type. In particular fold_binary folds the comparison {1,1,1} != {0,0,0} to false which causes the threader to register an incorrect jump thread. In general VEC1 != VEC2 gets folded as if it were VEC1 == VEC2. This patch fixes the problematic folding logic. Does this look OK to commit after bootstrap + regtesting? The faulty logic was introduced by the fix for PR68542 (r232518) so I think it is present on the 6 branch as well. gcc/ChangeLog: PR tree-optimization/71044 PR tree-optimization/68542 * fold-const.c (fold_relational_const): Fix folding of VECTOR_CST comparisons that have a scalar boolean result type. (test_vector_folding): New static function. (fold_const_c_tests): Call it. --- gcc/fold-const.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 30c1e0d..0271ac3 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -13897,7 +13897,6 @@ fold_relational_const (enum tree_code code, tree type, tree op0, tree op1) if (!VECTOR_TYPE_P (type)) { /* Have vector comparison with scalar boolean result. */ - bool result = true; gcc_assert ((code == EQ_EXPR || code == NE_EXPR) && VECTOR_CST_NELTS (op0) == VECTOR_CST_NELTS (op1)); for (unsigned i = 0; i < VECTOR_CST_NELTS (op0); i++) @@ -13905,11 +13904,12 @@ fold_relational_const (enum tree_code code, tree type, tree op0, tree op1) tree elem0 = VECTOR_CST_ELT (op0, i); tree elem1 = VECTOR_CST_ELT (op1, i); tree tmp = fold_relational_const (code, type, elem0, elem1); - result &= integer_onep (tmp); + if (tmp == NULL_TREE) + return NULL_TREE; + if (integer_zerop (tmp)) + return constant_boolean_node (false, type); } - if (code == NE_EXPR) - result = !result; - return constant_boolean_node (result, type); + return constant_boolean_node (true, type); } unsigned count = VECTOR_CST_NELTS (op0); tree *elts = XALLOCAVEC (tree, count); @@ -14517,12 +14517,32 @@ test_arithmetic_folding () x); } +/* Verify that various binary operations on vectors are folded + correctly. */ + +static void +test_vector_folding () +{ + tree inner_type = integer_type_node; + tree type = build_vector_type (inner_type, 4); + tree zero = build_zero_cst (type); + tree one = build_one_cst (type); + + /* Verify equality tests that return a scalar boolean result. */ + tree res_type = boolean_type_node; + ASSERT_FALSE (integer_nonzerop (fold_build2 (EQ_EXPR, res_type, zero, one))); + ASSERT_TRUE (integer_nonzerop (fold_build2 (EQ_EXPR, res_type, zero, zero))); + ASSERT_TRUE (integer_nonzerop (fold_build2 (NE_EXPR, res_type, zero, one))); + ASSERT_FALSE (integer_nonzerop (fold_build2 (NE_EXPR, res_type, one, one))); +} + /* Run all of the selftests within this file. */ void fold_const_c_tests () { test_arithmetic_folding (); + test_vector_folding (); } } // namespace selftest