From patchwork Wed Sep 20 12:18:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 113111 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp697707qgf; Wed, 20 Sep 2017 05:19:19 -0700 (PDT) X-Received: by 10.101.73.136 with SMTP id r8mr1938144pgs.67.1505909959353; Wed, 20 Sep 2017 05:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505909959; cv=none; d=google.com; s=arc-20160816; b=nHBtN/EQQVFSzyujVr3/l0Lg/cBXmsD+PdSW4m1EVsb7T1aYe9tcHfNJHyPcDOWg6s MydFkMtl/8JNKL/v6Wyt7+C3cs7LVNO9Sbujrj2Ax2PMdJKl0a2fS8m8vWs64WNEOnHY yu6QrP9YXUFeTcPH/sZCwIWN6Df7iYOqsiQc74ZCKhokVhj1hw+RItu22s1Vgc9TgGBS 9QZ1SosC7D6SbTsBEKYDgeAqaF69+D4fv7NbmEL87AHZQDkG+/J1d5i7CrLvweNW6aRP 3Cr9BXQhfzFBvBgx45StSKQnFnsGD0t3lBKyNGDR0mn182f7AMs5EvmYZRG6yf038Qw2 h1YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=naZ7LQpo6F3hK/oKJXkjUqrfbSpSNqHD9okjHOQv8eQ=; b=hfgWH8BKi0c+m1UDW0f7lFLedz/bnLEIbwO5o2i8C9GBNeCTFe6ogWMLs38XC/aXfa 0FVP7Ammbe8uFMZ6Jng8XqLt6/yTGaMWYJD9xhVMfDCqsFarAvKTakkPWJonowa1skoN vHgReOcaj/ChCvYiQwYS1KHUe0pkIbqjpDidFvKdwND3c3R+s0v/WrIre/GHHt4LdsSw YS338vCYeiGIgO/NOXCctwSLARqiplpyBEbTM6Rt+7JbQ0mDdln9QdGL1sKYtnlYS2cv 2GqUHCzI3SlCn55Wf6osdQAt0di2uMSXWD7I3Swt68RprDPqO1BeeHHe751xcES8rHxO RfNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=u701SQyk; spf=pass (google.com: domain of gcc-patches-return-462580-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462580-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 33si1273715plk.70.2017.09.20.05.19.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 05:19:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-462580-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=u701SQyk; spf=pass (google.com: domain of gcc-patches-return-462580-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462580-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=PUQUnl9dSUnmfZx+WPT/NFLEdkeYs43YLfephLYZm44nFNsxzvC2y Mwbq9rsascEZC1NWn9Saz4jADWGPLNsUyA3NW1DP0Y8QlJsTA8TGvYn8GtvwOdwF 8XLs+Hac7U8DjL9e9sVE+wjZUoDrYHy3F9LIr0HZtdZ2FhmCrRwj6c= 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 :to:subject:date:message-id:mime-version:content-type; s= default; bh=VzrXX/ImowKLbiNZJA54yhrGygk=; b=u701SQyk2CsdOVIF0HP1 XhHb67TYFRKeEkH45u8IQFrnlj/8yg2uQNObD0x4CLghWrNkKIorUI8KDFBeCSSr hfFBEwaMVcqEYwpEurL9JrvRFyXMYf4qh4zGHGbvmu2IfrOswipOOgVvrfEcIjrL jppAqwzJKJ/uNWEqh7/uLQs= Received: (qmail 24561 invoked by alias); 20 Sep 2017 12:18:47 -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 24466 invoked by uid 89); 20 Sep 2017 12:18:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=stood X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Sep 2017 12:18:45 +0000 Received: by mail-wm0-f49.google.com with SMTP id i189so6657267wmf.1 for ; Wed, 20 Sep 2017 05:18:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=naZ7LQpo6F3hK/oKJXkjUqrfbSpSNqHD9okjHOQv8eQ=; b=cfNvYTU4amEty1xbjfwsiNkg5Oicr2n32mIkYui6t24omTYsTZTZ/rDpwKKMQWal1j tp6+Xs8tEH3nD8V6crWI1EM4k1XFmqMuMtYmeNgpY+OpKbxL3RX4rGz9IqlRyURfOqfS gHNJNfawfYJxanMOsyXR2ZK5F/atb0NX6CsjYLUPt9GXd9MPSSNbugMRsGkkhjA+Mouj mvK/zr7Hy69WBY8GIEyVzm0uzH/LrXadImwyqldlIqXwM8xSqcOk+bi4OxCpnv+e7GNq B92wirsnqt7Fe6aOi5qG2Hj84eML26wwejZwetsvjqHB3GtFFvrPyd/H3OZIUxv4F7IQ LvSQ== X-Gm-Message-State: AHPjjUiWb7Vp+HEPS3tXEPlxRYu3Lv8d/RJJhfkmaaY8R+Mi/LTK33ys 1+du97iMbVokKKTci3NDOvxeRvdreF8= X-Google-Smtp-Source: AOwi7QCXAmeMEDXs8QM0CAGJNAlvQlihBI6N0zWwLfz2u4mT9IcgD15NaPIUqcSo6rUzGYqGic386Q== X-Received: by 10.28.105.12 with SMTP id e12mr3696981wmc.29.1505909922768; Wed, 20 Sep 2017 05:18:42 -0700 (PDT) Received: from localhost (92.40.248.127.threembb.co.uk. [92.40.248.127]) by smtp.gmail.com with ESMTPSA id b89sm1806899wrd.42.2017.09.20.05.18.41 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Sep 2017 05:18:41 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: match.pd handling of three-constant bitops Date: Wed, 20 Sep 2017 13:18:39 +0100 Message-ID: <87bmm51s2o.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 natch.pd tries to reassociate two bit operations if both of them have constant operands. However, with the polynomial integers added later, there's no guarantee that a bit operation on two integers can be folded at compile time. This means that the pattern can trigger for operations on three constants, and as things stood could endlessly oscillate between the two associations. This patch keeps the existing pattern for the normal case of a non-constant first operand. When all three operands are constant it tries to find a pair of constants that do fold. If none do, it keeps the original expression as-was. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linus-gnu. OK to install? Richard 2017-09-20 Richard Sandiford Alan Hayward David Sherwood gcc/ * match.pd: Handle bit operations involving three constants and try to fold one pair. Index: gcc/match.pd =================================================================== --- gcc/match.pd 2017-09-16 21:38:21.106513157 +0100 +++ gcc/match.pd 2017-09-20 13:17:10.552389270 +0100 @@ -1017,7 +1017,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for bitop (bit_and bit_ior bit_xor) (simplify (bitop (bitop @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2) - (bitop @0 (bitop @1 @2)))) + (if (!CONSTANT_CLASS_P (@0)) + (bitop @0 (bitop @1 @2)) + (with { tree cst1 = const_binop (bitop, type, @0, @2); } + (if (cst1) + (bitop @1 { cst1; }) + (with { tree cst2 = const_binop (bitop, type, @1, @2); } + (if (cst2) + (bitop @0 { cst2; })))))))) /* Try simple folding for X op !X, and X op X with the help of the truth_valued_p and logical_inverted_value predicates. */