From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 9DB6C385782D; Mon, 23 Aug 2021 03:11:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9DB6C385782D Received: by mail-pj1-x102a.google.com with SMTP id qe12-20020a17090b4f8c00b00179321cbae7so11173948pjb.2; Sun, 22 Aug 2021 20:11:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=2LSS028aUk1anM31r6fsA08dqHG6u7ciPPc6XL6kmik=; b=B0F1SZa3nUyxj8Wu2Ujcd8/B/IfL5M/umUme4En5vDAzkLg+foN9CffV3JAIryE0a0 NHSVNpipl/VnXnspIabzkMifUHVLnij8FXPo8lJchiVQ9snOvo7MFpjjspTY7tpXcL2V cO459q1LRTkLaHTt6wPQWZG2gWk2Oraulflb4VnVM47lEUTTP4nzLUkEd7Y352K9i7st hE4yK+tT/1csEI86ruqiugsfB57KS19IHEoFmfKLWWPHxe4ks6us3JOzV2HKKEc+eZsG bSuXF2itekv7LVQGsIEgQpuQill86uMTKJQFQlvipXXF55tlZAv+zW4GtPW7YrsABpH4 ntZw== X-Gm-Message-State: AOAM530UL0ssw7iIgui6FznU1HpXuVJUyHVlAKDUErXpfWjf7A2wd5IT zBUmWEf3706qNauE69OkwcQBnnzHSVZ58A== X-Google-Smtp-Source: ABdhPJxfcKK+JiOwDbtspfw1/3/DOYWUPzstOzNhVWl4nI3j2umGcMHdF3/chMO5lXciMF4HD0IC0w== X-Received: by 2002:a17:902:e850:b0:12d:ac12:1019 with SMTP id t16-20020a170902e85000b0012dac121019mr26695849plg.36.1629688269296; Sun, 22 Aug 2021 20:11:09 -0700 (PDT) Received: from [172.31.0.175] (c-98-202-48-222.hsd1.ut.comcast.net. [98.202.48.222]) by smtp.gmail.com with ESMTPSA id 65sm15968233pgi.12.2021.08.22.20.11.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Aug 2021 20:11:09 -0700 (PDT) Subject: Re: [PATCH] Propagate get_nonzero_bits information in division [PR77980] To: Victor Tong , "gcc-patches@gcc.gnu.org" , "pinskia@gcc.gnu.org" References: From: Jeff Law Message-ID: <110f4be7-8be8-a5ab-5637-e7717a4a1d35@gmail.com> Date: Sun, 22 Aug 2021 21:11:07 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Aug 2021 03:11:21 -0000 On 7/26/2021 6:45 PM, Victor Tong via Gcc-patches wrote: > This change enables the "t1 != 0" check to be optimized away in this code: > > int x1 = 0; > unsigned int x2 = 1; > > int main () > { > int t1 = x1*(1/(x2+x2)); > if (t1 != 0) __builtin_abort(); > return 0; > } > > The change utilizes the VRP framework to propagate the get_nonzero_bits information from the "x2+x2" expression to the "1/(x2+x2)" division expression. Specifically, the framework knows that the least significant bit of the "x2+x2" expression must be zero. > > The get_nonzero_bits information of the left hand side and right hand side of expressions needed to be passed down to operator_div::wi_fold() in the VRP framework. The majority of this change involves adding two additional parameters to propagate this information. There are future opportunities to use the non zero bit information to perform better optimizations in other types of expressions. > > The changes were tested against x86_64-pc-linux-gnu and all tests in "make -k check" passed. > > The original approach was to implement a match.pd pattern to support this but the pattern wasn't being triggered. More context is available in: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77980 So you're going to want to sync with Aldy & Andrew as they're the experts on the Ranger design & implementation.  This hits the Ranger API as well as design questions about how best to tie in the nonzero_bits capabilities. You might also want to reach out to Roger Sayle.  He's been poking around in a closely related area, though more focused on the bitwise conditional constant propagation rather than Ranger/VRP.  In fact, I just acked a patch of his that looks closely related. https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577888.html Jeff