[{"id":1772019,"web_url":"http://patchwork.ozlabs.org/comment/1772019/","msgid":"<CAFiYyc3sOKEg5vhumwOo9-R_fZMWVzeViopGsS60dqZoLZAGmA@mail.gmail.com>","list_archive_url":null,"date":"2017-09-20T15:58:59","subject":"Re: match.pd handling of three-constant bitops","submitter":{"id":1765,"url":"http://patchwork.ozlabs.org/api/people/1765/","name":"Richard Biener","email":"richard.guenther@gmail.com"},"content":"On Wed, Sep 20, 2017 at 2:18 PM, Richard Sandiford\n<richard.sandiford@linaro.org> wrote:\n> natch.pd tries to reassociate two bit operations if both of them have\n> constant operands.  However, with the polynomial integers added later,\n> there's no guarantee that a bit operation on two integers can be folded\n> at compile time.  This means that the pattern can trigger for operations\n> on three constants, and as things stood could endlessly oscillate\n> between the two associations.\n>\n> This patch keeps the existing pattern for the normal case of a\n> non-constant first operand.  When all three operands are constant it\n> tries to find a pair of constants that do fold.  If none do, it keeps\n> the original expression as-was.\n>\n> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linus-gnu.\n> OK to install?\n\nHmm, is the complication with trying variants necessary or could we simply do\n\n if (!CONSTANT_CLASS_P (@0))\n  (bitop @0 (bitop @1 @2))\n\nand be done with it?\n\n> Richard\n>\n>\n> 2017-09-20  Richard Sandiford  <richard.sandiford@linaro.org>\n>             Alan Hayward  <alan.hayward@arm.com>\n>             David Sherwood  <david.sherwood@arm.com>\n>\n> gcc/\n>         * match.pd: Handle bit operations involving three constants\n>         and try to fold one pair.\n>\n> Index: gcc/match.pd\n> ===================================================================\n> --- gcc/match.pd        2017-09-16 21:38:21.106513157 +0100\n> +++ gcc/match.pd        2017-09-20 13:17:10.552389270 +0100\n> @@ -1017,7 +1017,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n>  (for bitop (bit_and bit_ior bit_xor)\n>   (simplify\n>    (bitop (bitop @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)\n> -  (bitop @0 (bitop @1 @2))))\n> +  (if (!CONSTANT_CLASS_P (@0))\n> +   (bitop @0 (bitop @1 @2))\n> +   (with { tree cst1 = const_binop (bitop, type, @0, @2); }\n> +    (if (cst1)\n> +     (bitop @1 { cst1; })\n> +     (with { tree cst2 = const_binop (bitop, type, @1, @2); }\n> +      (if (cst2)\n> +       (bitop @0 { cst2; }))))))))\n>\n>  /* Try simple folding for X op !X, and X op X with the help\n>     of the truth_valued_p and logical_inverted_value predicates.  */","headers":{"Return-Path":"<gcc-patches-return-462616-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-462616-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"qdfgRLtv\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xy4Dj2j4sz9s7c\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 01:59:17 +1000 (AEST)","(qmail 13858 invoked by alias); 20 Sep 2017 15:59:09 -0000","(qmail 12819 invoked by uid 89); 20 Sep 2017 15:59:08 -0000","from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com)\n\t(74.125.82.52) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 20 Sep 2017 15:59:02 +0000","by mail-wm0-f52.google.com with SMTP id i189so8580809wmf.1 for\n\t<gcc-patches@gcc.gnu.org>; Wed, 20 Sep 2017 08:59:01 -0700 (PDT)","by 10.80.143.34 with HTTP; Wed, 20 Sep 2017 08:58:59 -0700 (PDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:in-reply-to:references:from:date:message-id\n\t:subject:to:content-type; q=dns; s=default; b=LfGiUAwBxZxO/7G5kw\n\ttdujXWbYB4/oW3UHBJ4KWGC6cNAoMIy/X4w4zDqhGZ5u2mN16ZSATpi/aj+OSkjh\n\tvXP1WU5IFk2jicYNzEN3FGlY1tD5hkOaF/1zMvIHD0CTL/b/nLTfZzD0NKivw0d9\n\t8m/+vphIGGYT37ojUmUr+voJM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:in-reply-to:references:from:date:message-id\n\t:subject:to:content-type; s=default; bh=NhlPBlwlLcd/jElUMaC76Shu\n\tx+0=; b=qdfgRLtv90UA9an6DHwEvn3ntv25Sx7z2xN7Ypiway5h8z2ArQjONFE9\n\thnHMRHbn+yKtA3En9EaXrMqzl6W9l44vNyQyQIKBVZ9HbsnHWSFm0g/1RhhYEmft\n\tZRmp6e+lFrUigFA5HyyxZTRF78BkvgCAPkCuIJWwgiXCfZcpQMI=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-10.5 required=5.0 tests=AWL, BAYES_00,\n\tFREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_SORBS_SPAM,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mail-wm0-f52.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to;\n\tbh=D3AEB2tb5VCgvGs3ij9m3VJ9fn6MjQ//ij1T6RTXTgc=;\n\tb=bcRmKWszseompadhhYoSZLawCC/lFBpFPcA+B2K8PTDxViGNrUL0j9ZU0ETtybsdtu\n\tjeW+RVu/XwB5dF3g+ZRmFyWARYjjxXWJ4xjocd4UYlbNydMB3OL60HzzPDrwL0eVCJXv\n\tFA75ZbrE2oUq460P99so7uOvWSCoNS7djplpr8Wq0NjUqj27TYr6isU79UNDmX8vSUV0\n\tfjCPbJvJYbRT1K+4S92HncmudC2b8on4NjhKCQXcKYiMQb2FvR6MBjA5PIqVgmPEnmCk\n\ts/noEfbUXn+QA8bCMmlT4jkCcnNqLEbS5GLC5d7OLoo8bUewjjLvdWrKEKVFzyR3k+5z\n\tOTwQ==","X-Gm-Message-State":"AHPjjUieOnKNrxTIT8iVIUqETPgZRp7Jbu8sPnvs6fIkTGQks5VqdNsA\t822TJedqQTTC86jrGPF47haJ9mxaJYsCjQ0OLRX0eQ==","X-Google-Smtp-Source":"AOwi7QBi9loYGykUJ2RRaSGotUtMPSQDaKF6/bP2jiREq/3XVtIbQpse23oeIK6Q+YkqFd+nQmNu5z6brcUCo6AVHOE=","X-Received":"by 10.80.217.15 with SMTP id t15mr4977799edj.217.1505923140145;\n\tWed, 20 Sep 2017 08:59:00 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<87bmm51s2o.fsf@linaro.org>","References":"<87bmm51s2o.fsf@linaro.org>","From":"Richard Biener <richard.guenther@gmail.com>","Date":"Wed, 20 Sep 2017 17:58:59 +0200","Message-ID":"<CAFiYyc3sOKEg5vhumwOo9-R_fZMWVzeViopGsS60dqZoLZAGmA@mail.gmail.com>","Subject":"Re: match.pd handling of three-constant bitops","To":"GCC Patches <gcc-patches@gcc.gnu.org>,\n\tRichard Sandiford <richard.sandiford@linaro.org>","Content-Type":"text/plain; charset=\"UTF-8\"","X-IsSubscribed":"yes"}},{"id":1772701,"web_url":"http://patchwork.ozlabs.org/comment/1772701/","msgid":"<878th85mis.fsf@linaro.org>","list_archive_url":null,"date":"2017-09-21T11:17:15","subject":"Re: match.pd handling of three-constant bitops","submitter":{"id":5450,"url":"http://patchwork.ozlabs.org/api/people/5450/","name":"Richard Sandiford","email":"richard.sandiford@linaro.org"},"content":"Richard Biener <richard.guenther@gmail.com> writes:\n> On Wed, Sep 20, 2017 at 2:18 PM, Richard Sandiford\n> <richard.sandiford@linaro.org> wrote:\n>> natch.pd tries to reassociate two bit operations if both of them have\n>> constant operands.  However, with the polynomial integers added later,\n>> there's no guarantee that a bit operation on two integers can be folded\n>> at compile time.  This means that the pattern can trigger for operations\n>> on three constants, and as things stood could endlessly oscillate\n>> between the two associations.\n>>\n>> This patch keeps the existing pattern for the normal case of a\n>> non-constant first operand.  When all three operands are constant it\n>> tries to find a pair of constants that do fold.  If none do, it keeps\n>> the original expression as-was.\n>>\n>> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linus-gnu.\n>> OK to install?\n>\n> Hmm, is the complication with trying variants necessary or could we simply do\n>\n>  if (!CONSTANT_CLASS_P (@0))\n>   (bitop @0 (bitop @1 @2))\n>\n> and be done with it?\n\nThat's enough to fix the oscillation, but there are cases that benefit\nfrom trying the other combinations.  E.g. if @1 and @2 are both\nINTEGER_CSTs, it's still worth folding them.  POLY_CST | INTEGER_CST\nis supported for some values, so if @0 | @1 doesn't fold, it's worth\ntrying @0 | @2 instead.\n\nThanks,\nRichard","headers":{"Return-Path":"<gcc-patches-return-462688-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-462688-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"KRNHUj9H\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xyYx80tMCz9sP1\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 21:17:30 +1000 (AEST)","(qmail 99471 invoked by alias); 21 Sep 2017 11:17:22 -0000","(qmail 98481 invoked by uid 89); 21 Sep 2017 11:17:21 -0000","from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com)\n\t(74.125.82.46) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 21 Sep 2017 11:17:20 +0000","by mail-wm0-f46.google.com with SMTP id m127so808257wmm.3 for\n\t<gcc-patches@gcc.gnu.org>; Thu, 21 Sep 2017 04:17:20 -0700 (PDT)","from localhost (92.40.249.45.threembb.co.uk. [92.40.249.45]) by\n\tsmtp.gmail.com with ESMTPSA id\n\tg25sm1506330wmc.16.2017.09.21.04.17.16 (version=TLS1_2\n\tcipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 21 Sep 2017 04:17:17 -0700 (PDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:references:date:in-reply-to:message-id\n\t:mime-version:content-type; q=dns; s=default; b=ib2+w51hndBttEpb\n\tFPh7q2tci9ZB96UfjSoQLBMs1O0U383Ue7fgJR3upLPQjhd6PZEZZfi1qwtUOhpG\n\tMeIrsXrCwQAWU8sQJxedl5hq4MiHNJmDrba7B1qmLth7FtHEYc5FYgVUEiz5CMmK\n\tKlo33+5/yH6lyr9wFOCxakQBOPU=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:references:date:in-reply-to:message-id\n\t:mime-version:content-type; s=default; bh=pI1+00efWWIdSyPkc0hblN\n\tmgrR8=; b=KRNHUj9HxLaKDC1UyArpCiCHx44O7UiCE+0Gg4m9yt+mQ4dbXozEIa\n\tDvRKszsMcarK2ksfbnoLWf6ErgIcelNi7h53eAv9HqGbhn2KD9FeA8GblPoaWlIf\n\thSSHriAsdmn+Q26EBjxz/pA0KVLqjI78ivSj6Gvkil2aCgVGcReyE=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-2.9 required=5.0 tests=AWL, BAYES_00,\n\tRCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=oscillation","X-HELO":"mail-wm0-f46.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:from:to:mail-followup-to:cc:subject:references\n\t:date:in-reply-to:message-id:user-agent:mime-version;\n\tbh=vJUsxJzS5Pqkix8ZR2ElUgfT23R5X3ZMT2x+zNyfUtc=;\n\tb=P3ocw5a2LIIS3MOR51ViBpTUKHTLvSD96oPVxjzHNI326me8l4c08bjVh8r297r1Qt\n\tRRL6+Hw5PzvRCOMky93Hz7km6+C5EL3h841ByStkB8i3MFILb+iSDVP7B1RlGX354FbN\n\tdQGQ5tYFHQAk6DLhdxrRmgdZv9ev31Ov/eDtYfHZcuZOIBAdZQYeYoWWEZGEBJj52P35\n\tAwaw7Dv9GSvh5XqLXgLZPhvEF98C8qX0xcdVsO8tY2G199E9isS/nzJWhSdTbh4GbRRM\n\tU+0wOhh7pNKuXvdl+LiW91H+xdQwO/C/N36pgXKnjWAwdoUOempQPG82wyEad/RWsCgP\n\tJMAA==","X-Gm-Message-State":"AHPjjUisQ4vTm1WnhgLsuWGG2v8YYQb6pr5RhrvPxkn9KrDoQiafj7he\trk5yf4/7XWAet/UFnHkrfzeetrY9Zds=","X-Google-Smtp-Source":"AOwi7QAGbsSfVfzHrPaAdz2zzT8Ts7z+Y9P2SMoR1oIVAWn9hS56GvY+6GElbF81+bjEeMNixdzI6A==","X-Received":"by 10.28.92.19 with SMTP id q19mr724127wmb.150.1505992638116;\n\tThu, 21 Sep 2017 04:17:18 -0700 (PDT)","From":"Richard Sandiford <richard.sandiford@linaro.org>","To":"Richard Biener <richard.guenther@gmail.com>","Mail-Followup-To":"Richard Biener <richard.guenther@gmail.com>,\n\tGCC Patches <gcc-patches@gcc.gnu.org>,\n\trichard.sandiford@linaro.org","Cc":"GCC Patches <gcc-patches@gcc.gnu.org>","Subject":"Re: match.pd handling of three-constant bitops","References":"<87bmm51s2o.fsf@linaro.org>\t<CAFiYyc3sOKEg5vhumwOo9-R_fZMWVzeViopGsS60dqZoLZAGmA@mail.gmail.com>","Date":"Thu, 21 Sep 2017 12:17:15 +0100","In-Reply-To":"<CAFiYyc3sOKEg5vhumwOo9-R_fZMWVzeViopGsS60dqZoLZAGmA@mail.gmail.com>\t(Richard\n\tBiener's message of \"Wed, 20 Sep 2017 17:58:59 +0200\")","Message-ID":"<878th85mis.fsf@linaro.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain"}},{"id":1772730,"web_url":"http://patchwork.ozlabs.org/comment/1772730/","msgid":"<CAFiYyc3OUWxYfM6Per8EqOv0sXRYBJ2JMkkbDD+mMf9j5Ct_=w@mail.gmail.com>","list_archive_url":null,"date":"2017-09-21T11:42:07","subject":"Re: match.pd handling of three-constant bitops","submitter":{"id":1765,"url":"http://patchwork.ozlabs.org/api/people/1765/","name":"Richard Biener","email":"richard.guenther@gmail.com"},"content":"On Thu, Sep 21, 2017 at 1:17 PM, Richard Sandiford\n<richard.sandiford@linaro.org> wrote:\n> Richard Biener <richard.guenther@gmail.com> writes:\n>> On Wed, Sep 20, 2017 at 2:18 PM, Richard Sandiford\n>> <richard.sandiford@linaro.org> wrote:\n>>> natch.pd tries to reassociate two bit operations if both of them have\n>>> constant operands.  However, with the polynomial integers added later,\n>>> there's no guarantee that a bit operation on two integers can be folded\n>>> at compile time.  This means that the pattern can trigger for operations\n>>> on three constants, and as things stood could endlessly oscillate\n>>> between the two associations.\n>>>\n>>> This patch keeps the existing pattern for the normal case of a\n>>> non-constant first operand.  When all three operands are constant it\n>>> tries to find a pair of constants that do fold.  If none do, it keeps\n>>> the original expression as-was.\n>>>\n>>> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linus-gnu.\n>>> OK to install?\n>>\n>> Hmm, is the complication with trying variants necessary or could we simply do\n>>\n>>  if (!CONSTANT_CLASS_P (@0))\n>>   (bitop @0 (bitop @1 @2))\n>>\n>> and be done with it?\n>\n> That's enough to fix the oscillation, but there are cases that benefit\n> from trying the other combinations.  E.g. if @1 and @2 are both\n> INTEGER_CSTs, it's still worth folding them.  POLY_CST | INTEGER_CST\n> is supported for some values, so if @0 | @1 doesn't fold, it's worth\n> trying @0 | @2 instead.\n\nHmm, ok.\n\nThe patch is ok then if you add a comment reflecting the above.\n\nThanks,\nRichard.\n\n>\n> Thanks,\n> Richard","headers":{"Return-Path":"<gcc-patches-return-462691-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-462691-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"d1jVhj5C\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xyZTm0Ybbz9s03\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 21:42:19 +1000 (AEST)","(qmail 66675 invoked by alias); 21 Sep 2017 11:42:11 -0000","(qmail 66626 invoked by uid 89); 21 Sep 2017 11:42:10 -0000","from mail-wm0-f48.google.com (HELO mail-wm0-f48.google.com)\n\t(74.125.82.48) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 21 Sep 2017 11:42:09 +0000","by mail-wm0-f48.google.com with SMTP id m72so486107wmc.0 for\n\t<gcc-patches@gcc.gnu.org>; Thu, 21 Sep 2017 04:42:09 -0700 (PDT)","by 10.80.143.34 with HTTP; Thu, 21 Sep 2017 04:42:07 -0700 (PDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:in-reply-to:references:from:date:message-id\n\t:subject:to:content-type; q=dns; s=default; b=hJ86tJahktIlhCZGoX\n\thxu9eV7YDnTTPwavnlWdz/FdwSn5SdcUyCU7JcWWAmDe/nlGFDxeLjxn+NoQf3Yt\n\tRHWYq49eoAp3XICGqI8cy0ZN9GErcFH+9ZgUt+EeAKJ8uTcVLaqnKqkl5fZ2JYQ0\n\t+z0JgyG/zeSACAtY9Lr5f0dFU=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:in-reply-to:references:from:date:message-id\n\t:subject:to:content-type; s=default; bh=A4eEuu7th0K8psN51Yrncp6v\n\t9Hc=; b=d1jVhj5CnloT+MylWsUXUocDgqKmjfrBCDdgTM/tltjDvt8K+jLD+sqb\n\tq/ClJeap9f3C8cVhhFn4cjPu0CdP0AMKedllIqy4zlPWZcLY7JTTKw+/JQCBXFQq\n\tqB4n9FWUeTRAU1tt9/yNcVnPYHtFRgHPkWvEgaduQtvPmgw6nXo=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-2.0 required=5.0 tests=AWL, BAYES_00,\n\tFREEMAIL_FROM, RCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mail-wm0-f48.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to;\n\tbh=KGgmQZBg4pKhlCPYXuLnOLcjzQMAzJ0gD4yfyLZy978=;\n\tb=UMniCju07EfHiRExkXbLkeaCicrHyjXh+tIaI1iLLrfXz271sHrCqKFHj1qf4hZi0k\n\tX/W2tkycjMf7KsYTaJ/jbVJCZBkYBUuKWfomN3Zpl/zqkSzhYpW2JmfPT6XxaZpd56Y7\n\t/HXkX+72cORPvz6wUhcJy57jYWCo4zjuhsrQGc/Dkp89SU+Y7OIi/MgIAuFUodwCPHHI\n\tRz9TjqmAft/Wr/68gu6lQlV1ghhbcri89YW6pzazb6COKaE2h5HtddSV9/q7MwKjFwSH\n\td7L47/3hn2PecCr9tjHhvfuJR0naQoK5nOsBimb3R5jbHaxjKNGhl6dJSnzpfiZnAdF3\n\t3onw==","X-Gm-Message-State":"AHPjjUj8Bg8eFFyXyN+j8yQ+XoAKJ3qV7yWNP4xjAhXcGcwfU6u7/jLG\tjCsZ+N/iS54K5n7T7wVnWnpGDKk4IxOzhpG0Jcg=","X-Google-Smtp-Source":"AOwi7QDl6HZrVAA9GP5dTLQK/kAxSXo4ifRVm0wkuCETbraQap6BhaemKSvlU3Y+FR/+APXtEvdF3f4ofVjkhtkqdC0=","X-Received":"by 10.80.146.56 with SMTP id i53mr910958eda.148.1505994127530;\n\tThu, 21 Sep 2017 04:42:07 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<878th85mis.fsf@linaro.org>","References":"<87bmm51s2o.fsf@linaro.org>\n\t<CAFiYyc3sOKEg5vhumwOo9-R_fZMWVzeViopGsS60dqZoLZAGmA@mail.gmail.com>\n\t<878th85mis.fsf@linaro.org>","From":"Richard Biener <richard.guenther@gmail.com>","Date":"Thu, 21 Sep 2017 13:42:07 +0200","Message-ID":"<CAFiYyc3OUWxYfM6Per8EqOv0sXRYBJ2JMkkbDD+mMf9j5Ct_=w@mail.gmail.com>","Subject":"Re: match.pd handling of three-constant bitops","To":"Richard Biener <richard.guenther@gmail.com>,\n\tGCC Patches <gcc-patches@gcc.gnu.org>,\n\tRichard Sandiford <richard.sandiford@linaro.org>","Content-Type":"text/plain; charset=\"UTF-8\"","X-IsSubscribed":"yes"}},{"id":1831021,"web_url":"http://patchwork.ozlabs.org/comment/1831021/","msgid":"<87fu7nv1ya.fsf@linaro.org>","list_archive_url":null,"date":"2018-01-03T07:25:17","subject":"Re: match.pd handling of three-constant bitops","submitter":{"id":5450,"url":"http://patchwork.ozlabs.org/api/people/5450/","name":"Richard Sandiford","email":"richard.sandiford@linaro.org"},"content":"Richard Biener <richard.guenther@gmail.com> writes:\n> On Thu, Sep 21, 2017 at 1:17 PM, Richard Sandiford\n> <richard.sandiford@linaro.org> wrote:\n>> Richard Biener <richard.guenther@gmail.com> writes:\n>>> On Wed, Sep 20, 2017 at 2:18 PM, Richard Sandiford\n>>> <richard.sandiford@linaro.org> wrote:\n>>>> natch.pd tries to reassociate two bit operations if both of them have\n>>>> constant operands.  However, with the polynomial integers added later,\n>>>> there's no guarantee that a bit operation on two integers can be folded\n>>>> at compile time.  This means that the pattern can trigger for operations\n>>>> on three constants, and as things stood could endlessly oscillate\n>>>> between the two associations.\n>>>>\n>>>> This patch keeps the existing pattern for the normal case of a\n>>>> non-constant first operand.  When all three operands are constant it\n>>>> tries to find a pair of constants that do fold.  If none do, it keeps\n>>>> the original expression as-was.\n>>>>\n>>>> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linus-gnu.\n>>>> OK to install?\n>>>\n>>> Hmm, is the complication with trying variants necessary or could we simply do\n>>>\n>>>  if (!CONSTANT_CLASS_P (@0))\n>>>   (bitop @0 (bitop @1 @2))\n>>>\n>>> and be done with it?\n>>\n>> That's enough to fix the oscillation, but there are cases that benefit\n>> from trying the other combinations.  E.g. if @1 and @2 are both\n>> INTEGER_CSTs, it's still worth folding them.  POLY_CST | INTEGER_CST\n>> is supported for some values, so if @0 | @1 doesn't fold, it's worth\n>> trying @0 | @2 instead.\n>\n> Hmm, ok.\n>\n> The patch is ok then if you add a comment reflecting the above.\n\nThanks.  For the record, here's what I installed after retesting.\n\nRichard\n\n\n2018-01-03  Richard Sandiford  <richard.sandiford@linaro.org>\n\t    Alan Hayward  <alan.hayward@arm.com>\n\t    David Sherwood  <david.sherwood@arm.com>\n\ngcc/\n\t* match.pd: Handle bit operations involving three constants\n\tand try to fold one pair.\n------------------------------------------------------------------------------\n\nIndex: gcc/match.pd\n===================================================================\n--- gcc/match.pd\t2018-01-02 16:55:03.498204314 +0000\n+++ gcc/match.pd\t2018-01-03 07:10:06.993953631 +0000\n@@ -1111,7 +1111,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n (for bitop (bit_and bit_ior bit_xor)\n  (simplify\n   (bitop (bitop @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)\n-  (bitop @0 (bitop @1 @2))))\n+  (if (!CONSTANT_CLASS_P (@0))\n+   /* This is the canonical form regardless of whether (bitop @1 @2) can be\n+      folded to a constant.  */\n+   (bitop @0 (bitop @1 @2))\n+   /* In this case we have three constants and (bitop @0 @1) doesn't fold\n+      to a constant.  This can happen if @0 or @1 is a POLY_INT_CST and if\n+      the values involved are such that the operation can't be decided at\n+      compile time.  Try folding one of @0 or @1 with @2 to see whether\n+      that combination can be decided at compile time.\n+\n+      Keep the existing form if both folds fail, to avoid endless\n+      oscillation.  */\n+   (with { tree cst1 = const_binop (bitop, type, @0, @2); }\n+    (if (cst1)\n+     (bitop @1 { cst1; })\n+     (with { tree cst2 = const_binop (bitop, type, @1, @2); }\n+      (if (cst2)\n+       (bitop @0 { cst2; }))))))))\n \n /* Try simple folding for X op !X, and X op X with the help\n    of the truth_valued_p and logical_inverted_value predicates.  */","headers":{"Return-Path":"<gcc-patches-return-470027-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-470027-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"xmmGNZE8\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3zBMsX27kJz9s81\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  3 Jan 2018 18:25:34 +1100 (AEDT)","(qmail 129690 invoked by alias); 3 Jan 2018 07:25:25 -0000","(qmail 129675 invoked by uid 89); 3 Jan 2018 07:25:25 -0000","from mail-wm0-f48.google.com (HELO mail-wm0-f48.google.com)\n\t(74.125.82.48) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 03 Jan 2018 07:25:22 +0000","by mail-wm0-f48.google.com with SMTP id y82so18993062wmg.1 for\n\t<gcc-patches@gcc.gnu.org>; Tue, 02 Jan 2018 23:25:22 -0800 (PST)","from localhost ([95.144.14.233]) by smtp.gmail.com with ESMTPSA id\n\to98sm2191107wrb.40.2018.01.02.23.25.18 (version=TLS1_2\n\tcipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 02 Jan 2018 23:25:19 -0800 (PST)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:references:date:in-reply-to:message-id\n\t:mime-version:content-type; q=dns; s=default; b=rbC90U0LO0O0jstz\n\tisrB0itvujjp3TwAP0QuuxsnC3JVE+zMRnZ79lLbuGCM4iweoFsO4YmoluYOQ6kh\n\tyDQ/TZXEBo7DPdA3lO+9LwLGLOGSIV3TX8w55+IIoUWzc7gqUsVfyEwAf4E3SsJe\n\tozR226vctrI6qIIS68qVFT2YQWw=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:references:date:in-reply-to:message-id\n\t:mime-version:content-type; s=default; bh=7lgeAiRRgmgy1kMLu8vj+N\n\t398Ug=; b=xmmGNZE8j62snV6p4uOnIy99BtpY8dVVYtLvTcPouJUPzvgvsxvhRC\n\tZC9Y3SZLdCR72G/X5vJTjn8cEVbgFDs1Gk0mrAlThqYEWp4TObY+SrYFVBvyYrA2\n\tFyA1PHImNT1Sm+Rkz1SQCAn4o0Chh6ac4gTxCRutzCdIOJYzNMl6Y=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-11.7 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS,\n\tRCVD_IN_DNSWL_NONE,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=complication,\n\tendless, stood, Hx-languages-length:3356","X-HELO":"mail-wm0-f48.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:from:to:mail-followup-to:cc:subject:references\n\t:date:in-reply-to:message-id:user-agent:mime-version;\n\tbh=sJ7jh6dGYGmUFsQqDrd5nP5m3eo+LxQJtxdTuSlMgBQ=;\n\tb=HH9eOnFNRPJD6fEtTan8H6Z9S2O1EEmQuDPC866GbMVoAS3KMlnQCME4Qfg8vuNmuK\n\teSvvtDHV+OwWtMhftTo0ERDJ2gFZVReEpksdy+IzkdiR/qf/R+a/C21A6GBjDVWdTxpG\n\t0HWWcK7ORsBKR/q0OqQpJzKs+UETAdMd/OYJuFjaQ7K1yBjxSRgK70ZqGlVaysqCCI8B\n\tSoXnRMnrW6WwollyKCR85uStI3O0VMljrKC5WjVffHZ19oUultNgtd2KsGGC9YuMBHtN\n\tveOJBAspArqYmFZY+AKT3VfTa/VZa6972QhLLsdfI+7XQUCfAXmuImY+yLWEVZYZs+7G\n\t73nA==","X-Gm-Message-State":"AKGB3mIk0r0kbD8aNRmBYtJsATQBT2JiWTxpX7OH4Yh9oAbMhlJ/SPdv\tlRVyo6UBLv9Pu3beKxoXJztN/PMsC5c=","X-Google-Smtp-Source":"ACJfBosKzY0Ly2veJMVATNMJZEwkXPa/chJWJIhi6Mfup7QQl90T2vcDQwquemCpFwEFjHMQxdbhrQ==","X-Received":"by 10.28.106.6 with SMTP id f6mr563208wmc.111.1514964320460;\n\tTue, 02 Jan 2018 23:25:20 -0800 (PST)","From":"Richard Sandiford <richard.sandiford@linaro.org>","To":"Richard Biener <richard.guenther@gmail.com>","Mail-Followup-To":"Richard Biener <richard.guenther@gmail.com>,\n\tGCC Patches <gcc-patches@gcc.gnu.org>,\n\trichard.sandiford@linaro.org","Cc":"GCC Patches <gcc-patches@gcc.gnu.org>","Subject":"Re: match.pd handling of three-constant bitops","References":"<87bmm51s2o.fsf@linaro.org>\t<CAFiYyc3sOKEg5vhumwOo9-R_fZMWVzeViopGsS60dqZoLZAGmA@mail.gmail.com>\t<878th85mis.fsf@linaro.org>\t<CAFiYyc3OUWxYfM6Per8EqOv0sXRYBJ2JMkkbDD+mMf9j5Ct_=w@mail.gmail.com>","Date":"Wed, 03 Jan 2018 07:25:17 +0000","In-Reply-To":"<CAFiYyc3OUWxYfM6Per8EqOv0sXRYBJ2JMkkbDD+mMf9j5Ct_=w@mail.gmail.com>\t(Richard\n\tBiener's message of \"Thu, 21 Sep 2017 13:42:07 +0200\")","Message-ID":"<87fu7nv1ya.fsf@linaro.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain"}}]