From patchwork Sat Mar 14 09:10:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 450174 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 85D1714008F for ; Sat, 14 Mar 2015 20:10:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=nQDrOXaf; dkim-adsp=none (unprotected policy); 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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=uKfG5mAie9zNr5J1AsX6XPe294Iqp WAA9wOXRY2yQwx/wfDFg0kWAak/BhswmnPLldgE3Ky9HMLKEu96+jo+7fCoqyy1Y AO/5V7TY1hH+xAYB5254D5sjP4zhKQix7idMl/2hjQz3MBHehLhgmepkglvepqq+ tW/MTfE9gM3sBE= 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:mime-version :content-type; s=default; bh=nkiqRJt3kTIeFl4wsEURxJnlZ0E=; b=nQD rOXafBgt0szULLugvOfvhuZ5/QOvRaNLkIBMu4dZfXKjhpgQAfx+PKqZW2eCJrym 2HMqDJ4srgKmwtgGbRv6he/le0XoNUtsHl8zH8LSLS28/1BuXUumX/cxpm5H7rVc A8x7C6m3JNuwV0Jj9VMFe4adaYEQ5iHxeF1TlrbA= Received: (qmail 116455 invoked by alias); 14 Mar 2015 09:10:42 -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 116442 invoked by uid 89); 14 Mar 2015 09:10:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 14 Mar 2015 09:10:40 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2E9Adux000434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 14 Mar 2015 05:10:39 -0400 Received: from tucnak.zalov.cz (ovpn-116-63.ams2.redhat.com [10.36.116.63]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2E9Ab94022582 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Sat, 14 Mar 2015 05:10:38 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.9/8.14.9) with ESMTP id t2E9AZQt016949; Sat, 14 Mar 2015 10:10:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.9/8.14.9/Submit) id t2E9AYkb016948; Sat, 14 Mar 2015 10:10:34 +0100 Date: Sat, 14 Mar 2015 10:10:34 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix reassoc bit test optimization (PR tree-optimization/65418) Message-ID: <20150314091034.GK1746@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi! The first testcase shows a bug in my bit test reassoc optimization, extract_bit_test_mask is (intentionally) stripping nops, but was setting *totallowp and operating with tbias in the type of unstripped expression, which then results in different signedness of types used and confusing the optimization. In particular, -218 and -216 are already folded into (x is signed int) (((unsigned) x + 218U) & -2U) == 0 and thus without the patch we set lowi in the parent to -218U. Then -146 and -132 are just x == -146 and x == -132 thus we were comparing -218U to -146 or -132. But we really want to use -218 instead, as that is the type of x. Fixed thusly, bootstrapped/regtested on {x86_64,i686,aarch64,powerpc64{,le},s390{,x}}-linux, ok for trunk? 2015-03-14 Jakub Jelinek PR tree-optimization/65418 * tree-ssa-reassoc.c (extract_bit_test_mask): If there are casts in the first PLUS_EXPR operand, ensure tbias and *totallowp are in the inner type. * gcc.c-torture/execute/pr65418-1.c: New test. * gcc.c-torture/execute/pr65418-2.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2015-02-26 22:02:39.000000000 +0100 +++ gcc/tree-ssa-reassoc.c 2015-03-13 16:22:50.506295252 +0100 @@ -2439,26 +2439,25 @@ extract_bit_test_mask (tree exp, int pre && TREE_CODE (exp) == PLUS_EXPR && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST) { + tree ret = TREE_OPERAND (exp, 0); + STRIP_NOPS (ret); widest_int bias = wi::neg (wi::sext (wi::to_widest (TREE_OPERAND (exp, 1)), TYPE_PRECISION (TREE_TYPE (low)))); - tree tbias = wide_int_to_tree (TREE_TYPE (low), bias); + tree tbias = wide_int_to_tree (TREE_TYPE (ret), bias); if (totallowp) { *totallowp = tbias; - exp = TREE_OPERAND (exp, 0); - STRIP_NOPS (exp); - return exp; + return ret; } else if (!tree_int_cst_lt (totallow, tbias)) return NULL_TREE; + bias = wi::to_widest (tbias); bias -= wi::to_widest (totallow); if (wi::ges_p (bias, 0) && wi::lts_p (bias, prec - max)) { *mask = wi::lshift (*mask, bias); - exp = TREE_OPERAND (exp, 0); - STRIP_NOPS (exp); - return exp; + return ret; } } } --- gcc/testsuite/gcc.c-torture/execute/pr65418-1.c.jj 2015-03-13 16:49:07.973604649 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr65418-1.c 2015-03-13 16:48:28.000000000 +0100 @@ -0,0 +1,19 @@ +/* PR tree-optimization/65418 */ + +__attribute__((noinline, noclone)) int +foo (int x) +{ + if (x == -216 || x == -132 || x == -218 || x == -146) + return 1; + return 0; +} + +int +main () +{ + volatile int i; + for (i = -230; i < -120; i++) + if (foo (i) != (i == -216 || i == -132 || i == -218 || i == -146)) + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.c-torture/execute/pr65418-2.c.jj 2015-03-13 16:49:10.992556110 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr65418-2.c 2015-03-13 16:48:44.000000000 +0100 @@ -0,0 +1,19 @@ +/* PR tree-optimization/65418 */ + +__attribute__((noinline, noclone)) int +foo (int x) +{ + if (x == -216 || x == -211 || x == -218 || x == -205 || x == -223) + return 1; + return 0; +} + +int +main () +{ + volatile int i; + for (i = -230; i < -200; i++) + if (foo (i) != (i == -216 || i == -211 || i == -218 || i == -205 || i == -223)) + __builtin_abort (); + return 0; +}