From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30791 invoked by alias); 19 Oct 2015 11:40:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 30772 invoked by uid 89); 19 Oct 2015 11:40:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail3-relais-sop.national.inria.fr Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 19 Oct 2015 11:40:16 +0000 Received: from 89-158-40-219.rev.numericable.fr (HELO laptop-mg.local) ([89.158.40.219]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2015 13:40:12 +0200 Date: Mon, 19 Oct 2015 11:42:00 -0000 From: Marc Glisse To: "Hurugalawadi, Naveen" cc: Richard Biener , "gcc-patches@gcc.gnu.org" Subject: Re: Move some bit and binary optimizations in simplify and match In-Reply-To: Message-ID: References: , , User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-SW-Source: 2015-10/txt/msg01729.txt.bz2 +/* Fold X + (X / CST) * -CST to X % CST. */ This one is still wrong. It is extremely similar to X-(X/CST)*CST, and the current version of that one in match.pd is broken, we should fix that one first. +/* Fold (A & ~B) - (A & B) into (A ^ B) - B. */ +(simplify + (minus (bit_and:s @0 (bit_not @1)) (bit_and:s @0 @1)) + (if (! FLOAT_TYPE_P (type)) + (minus (bit_xor @0 @1) @1))) I don't understand the point of the FLOAT_TYPE_P check. Will we also simplify (A & B) - (A & ~B) into B - (A ^ B) ? +(simplify + (minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1)) + (if (! FLOAT_TYPE_P (type) + && wi::eq_p (const_unop (BIT_NOT_EXPR, TREE_TYPE (type), @2), @1)) TREE_TYPE (type) ??? + (minus (bit_xor @0 @1) @1))) (just a random comment, not for your patch) When we generalize this to vector, should that be: operand_equal_p (const_unop (BIT_NOT_EXPR, type, @2), @1, OEP_ONLY_CONST) or maybe integer_all_onesp (const_binop (BIT_XOR_EXPR, type, @2, @1)) ? +/* Simplify (X & ~Y) | (~X & Y) -> X ^ Y. */ +(simplify + (bit_ior (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1)) + (bit_xor @0 @1)) :c on bit_ior? It should also allow you to merge the 2 CST versions into one. + (bit_ior (bit_and:c INTEGER_CST@0 (bit_not @1)) (bit_and:c (bit_not INTEGER_CST@2) @1)) gcc always puts the constant last in bit_and, so (bit_and (bit_not @1) INTEGER_CST@0) You still have a (bit_not INTEGER_CST@2)... -/* X & !X -> 0. */ +/* X & !X or X & ~X -> 0. */ (simplify (bit_and:c @0 (logical_inverted_value @0)) - { build_zero_cst (type); }) + { build_zero_cst (type); }) /* X | !X and X ^ !X -> 1, , if X is truth-valued. */ (for op (bit_ior bit_xor) (simplify I think that was already in your other patch, and I am not really in favor of the indentation change (or the comment). -- Marc Glisse