From patchwork Fri Oct 25 22:19:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 286233 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AAB2B2C00CC for ; Sat, 26 Oct 2013 09:19:46 +1100 (EST) 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:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=WJNy8p/E/1qTmd7ex cZ8ECTxtdMaBOe7b+7q/21RwCVJIYAB66KkoAR6ms1eZHuA0HgGvmlP4HlRebUXY XypwbTlqQwXf5+ufWbNhWglwmhjot7PoJXU7yi5TcFwtfp9eLtuqikeVpxaP0Uev BMzqco60trVtbxWVtcEN4fEn5M= 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:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=2oIRJTBiRRzJ2INr0Zsw3sA LRsw=; b=ElVtj920Yt/Zwgk3HFr4Um4WPXlpgX5ZYRA01ZRGVY6HW3yNi4kHX6D idsVW5h4c/i8LXs1Dsiyp+uQQmYdaAOTKHUXB/JzwDbWbbo7PGKcN5IQVsrPkvJf QQLJPUdVD4c8eUKHndsnkneRq7rNxTP2i09/23u/XdcuRXU8Rlq4= Received: (qmail 5843 invoked by alias); 25 Oct 2013 22:19:40 -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 5827 invoked by uid 89); 25 Oct 2013 22:19:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 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; Fri, 25 Oct 2013 22:19:38 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9PMJaGR026494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 25 Oct 2013 18:19:37 -0400 Received: from tucnak.zalov.cz (vpn1-6-237.ams2.redhat.com [10.36.6.237]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r9PMJZdA004243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 25 Oct 2013 18:19:36 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id r9PMJYJE021421; Sat, 26 Oct 2013 00:19:34 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id r9PMJXpH021420; Sat, 26 Oct 2013 00:19:33 +0200 Date: Sat, 26 Oct 2013 00:19:33 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Compute nonzero_bits from __builtin_unreachable assertions Message-ID: <20131025221933.GN30970@tucnak.zalov.cz> Reply-To: Jakub Jelinek References: <20131025091925.GG30970@tucnak.zalov.cz> <20131025173844.GK30970@tucnak.zalov.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20131025173844.GK30970@tucnak.zalov.cz> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! And here is a patch that allows vectorization without peeling for alignment and scalar loop for bound even for fn2, fn3 and fn4 in the following testcase, though as with the range __builtin_unreachable () notes, it is quite fragile, because it only works if there are no immediate uses of the tested SSA_NAME before the assertion. Perhaps more reliable way would be to convert those assertions info __builtin_assume_aligned, but that has the disadvantage that it's first argument is a pointer and it returns a pointer, so we'd need to cast integers to pointers and back, or add ASSUME_ALIGNED internal function. Bootstrapped/regtested on x86_64-linux and i686-linux. int a[1024]; void fn1 (int x, int y) { int i; x &= -32; y &= -32; for (i = x + 32; i < y; i++) a[i]++; } void fn2 (int x, int y) { int i; if (x & 31) __builtin_unreachable (); if (y & 31) __builtin_unreachable (); for (i = x + 32; i < x + y; i++) a[i]++; } void fn3 (int x, int y) { int i; if (x % 32) __builtin_unreachable (); if (y % 32) __builtin_unreachable (); for (i = x + 32; i < x + y; i++) a[i]++; } void fn3 (int x, int y) { int i; if ((x % 32) != 0) __builtin_unreachable (); if ((y % 32) != 0) __builtin_unreachable (); for (i = x + 32; i < x + y; i++) a[i]++; } 2013-10-25 Jakub Jelinek * tree-vrp.c (maybe_set_nonzero_bits): New function. (remove_range_assertions): Call it. Jakub --- gcc/tree-vrp.c.jj 2013-10-24 14:32:29.000000000 +0200 +++ gcc/tree-vrp.c 2013-10-25 21:21:35.183092937 +0200 @@ -6459,6 +6459,60 @@ check_all_array_refs (void) } } +/* Handle + _4 = x_3 & 31; + if (_4 != 0) + goto ; + else + goto ; + : + __builtin_unreachable (); + : + x_5 = ASSERT_EXPR ; + If x_3 has no other immediate uses (checked by caller), + var is the x_3 var from ASSERT_EXPR, we can clear low 5 bits + from the non-zero bitmask. */ + +static void +maybe_set_nonzero_bits (basic_block bb, tree var) +{ + edge e = single_pred_edge (bb); + basic_block cond_bb = e->src; + gimple stmt = last_stmt (cond_bb); + tree cst; + + if (stmt == NULL + || gimple_code (stmt) != GIMPLE_COND + || gimple_cond_code (stmt) != ((e->flags & EDGE_TRUE_VALUE) + ? EQ_EXPR : NE_EXPR) + || TREE_CODE (gimple_cond_lhs (stmt)) != SSA_NAME + || !integer_zerop (gimple_cond_rhs (stmt))) + return; + + stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (stmt)); + if (!is_gimple_assign (stmt) + || gimple_assign_rhs_code (stmt) != BIT_AND_EXPR + || TREE_CODE (gimple_assign_rhs2 (stmt)) != INTEGER_CST) + return; + if (gimple_assign_rhs1 (stmt) != var) + { + gimple stmt2; + + if (TREE_CODE (gimple_assign_rhs1 (stmt)) != SSA_NAME) + return; + stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt)); + if (!gimple_assign_cast_p (stmt2) + || gimple_assign_rhs1 (stmt2) != var + || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt2)) + || (TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt))) + != TYPE_PRECISION (TREE_TYPE (var)))) + return; + } + cst = gimple_assign_rhs2 (stmt); + set_nonzero_bits (var, (get_nonzero_bits (var) + & ~tree_to_double_int (cst))); +} + /* Convert range assertion expressions into the implied copies and copy propagate away the copies. Doing the trivial copy propagation here avoids the need to run the full copy propagation pass after @@ -6576,8 +6630,11 @@ remove_range_assertions (void) } } if (ok) - set_range_info (var, SSA_NAME_RANGE_INFO (lhs)->min, - SSA_NAME_RANGE_INFO (lhs)->max); + { + set_range_info (var, SSA_NAME_RANGE_INFO (lhs)->min, + SSA_NAME_RANGE_INFO (lhs)->max); + maybe_set_nonzero_bits (bb, var); + } } }