From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91442 invoked by alias); 22 Jul 2015 11:54:56 -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 91433 invoked by uid 89); 22 Jul 2015 11:54:55 -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,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f182.google.com Received: from mail-ie0-f182.google.com (HELO mail-ie0-f182.google.com) (209.85.223.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 22 Jul 2015 11:54:54 +0000 Received: by iecri3 with SMTP id ri3so70378167iec.2 for ; Wed, 22 Jul 2015 04:54:52 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.59.211 with SMTP id b19mr33085767igr.42.1437566092522; Wed, 22 Jul 2015 04:54:52 -0700 (PDT) Received: by 10.107.142.7 with HTTP; Wed, 22 Jul 2015 04:54:52 -0700 (PDT) In-Reply-To: References: Date: Wed, 22 Jul 2015 12:10:00 -0000 Message-ID: Subject: Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF) From: Richard Biener To: "Hurugalawadi, Naveen" Cc: "marc.glisse@inria.fr" , GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg01829.txt.bz2 On Tue, Jul 21, 2015 at 11:16 AM, Hurugalawadi, Naveen wrote: > Hi, > >>> For signed types with TYPE_OVERFLOW_UNDEFINED >>> you can simply cancel the operation (even for non-power-of-two multipliers). > > Thanks for the review and comments. > > Please find attached the modified patch as per your comments. > > Please review the same and let me know if any further modifications are required. > > Regression Tested on X86_64. @@ -280,6 +280,20 @@ along with GCC; see the file COPYING3. If not see && integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0) (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))))) +/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF. */ +(simplify + (exact_div (mult @0 INTEGER_CST@1) @1) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + @0)) The comment applies to the pattern below and the pattern above lacks a comment +(simplify + (trunc_div (mult @0 integer_pow2p@1) @1) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (with { tree n2 = build_int_cst (TREE_TYPE (@0), + wi::exact_log2 (@1)); } + (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); } + { n2; }) { n2; }))))) please use (with { int n2 = wi::exact_log2 (@1); tree mask = wide_int_to_tree (type, wi::rshift (wi::lshift (-1, n2), n2)); } (bit_and @0 { mask; })))) in fact, the -1 << log2 >> log2 looks like it does wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1), false, TYPE_PRECISION (type)); so using wi::mask is prefered here. Thanks, Richard. > Thanks, > Naveen > > gcc/testsuite/ChangeLog: > > 2015-07-21 Naveen H.S > > PR middle-end/25529 > * gcc.dg/pr25529.c: New test. > > gcc/ChangeLog: > > 2015-07-21 Naveen H.S > > PR middle-end/25529 > * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) : New simplifier. > (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.