From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 3D6163858010 for ; Sat, 30 Jul 2022 15:38:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3D6163858010 Received: by mail-pg1-x52b.google.com with SMTP id bh13so6230564pgb.4 for ; Sat, 30 Jul 2022 08:38:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ZU7w9kolcAwd/41WIBXmkCTX3q6944f9ai+o5c2xi64=; b=yPrOdbYe9gm8zcRy7lVNRrrVPmy/9y64UtSi8vqo8X/ZGH2CSRTMFi+JPb/zC22Rff IaQGxzBBekC07tSNrGhgfPhOTuNVXsluhB/Q9FTJQPhDtoodxLVWyxjb75fILBq2x2aC d9tFob0IbW59M7e+1G4iLp1rJBqbmX95s/UXKxuK7awZp2+bo6Li4QcG/vQDhmEqgI1Z 9bjAyN3f4a90ZO/jICbuu5LdZvpOSztGG5uenMI/3a+ZRrWIi8HmI6PzI6/GcmZufPIX jaFUJKBN6jp0h7RYPP/43oJNv/DeRHG/846lcJohQb4AZBLDbCUuiddD5o7rFAKSnSpy hptA== X-Gm-Message-State: AJIora8FSX2nbsDyTNLziOiee9B14Fsjb8ir1Oe/MswZsKYSjYd2EzJR ioijF0MolwqlCmjpMHmTCJskojUb93I= X-Google-Smtp-Source: AGRyM1urv2uDQrYj62ofushLP4cWOJOl6iSQAZA+p7eK9yMIUhoafNgRbuaw39M3x6hiGk0S3hmiYA== X-Received: by 2002:a63:1f61:0:b0:41a:8b08:2a1d with SMTP id q33-20020a631f61000000b0041a8b082a1dmr6876952pgm.301.1659195525550; Sat, 30 Jul 2022 08:38:45 -0700 (PDT) Received: from [172.31.0.204] (c-73-98-188-51.hsd1.ut.comcast.net. [73.98.188.51]) by smtp.gmail.com with ESMTPSA id w23-20020a170902a71700b0016dc26c7d30sm5844413plq.164.2022.07.30.08.38.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Jul 2022 08:38:44 -0700 (PDT) Message-ID: <1ec62706-b9eb-0449-70d8-fbeab76458b5@gmail.com> Date: Sat, 30 Jul 2022 09:38:43 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] tree-optimization/105679 - disable backward threading of unlikely entry Content-Language: en-US To: gcc-patches@gcc.gnu.org References: <20220729085417.4B50F13A1B@imap2.suse-dmz.suse.de> From: Jeff Law In-Reply-To: <20220729085417.4B50F13A1B@imap2.suse-dmz.suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sat, 30 Jul 2022 15:38:48 -0000 On 7/29/2022 2:54 AM, Richard Biener via Gcc-patches wrote: > The following makes the backward threader reject threads whose entry > edge is probably never executed according to the profile. That in > particular, for the testcase, avoids threading the irq == 1 check > on the path where irq > 31, thereby avoiding spurious -Warray-bounds > diagnostics > > if (irq_1(D) > 31) > goto ; [0.00%] > else > goto ; [100.00%] > > ;; basic block 3, loop depth 0, count 0 (precise), probably never executed > _2 = (unsigned long) irq_1(D); > __builtin___ubsan_handle_shift_out_of_bounds (&*.Lubsan_data0, 1, _2); > > _3 = 1 << irq_1(D); > mask_4 = (u32) _3; > entry = instance_5(D)->array[irq_1(D)]; > capture (mask_4); > if (level_6(D) != 0) > goto ; [34.00%] > else > goto ; [66.00%] > > ;; basic block 5, loop depth 0, count 708669600 (estimated locally), maybe hot if (irq_1(D) == 1) > goto ; [20.97%] > else > goto ; [79.03%] > > Bootstrap and regtest running on x86_64-unknown-linux-gnu. > > The testcase in the PR requries both ubsan and sancov so I'm not sure > where to put it but IIRC there were quite some duplicate PRs wrt > threading unlikely paths exposing diagnostics, eventually some > testcase will come out of those (when we identify them). Note > the patch is quite conservative in only disabling likely never > executed paths rather than requiring maybe_hot_edge_p (OTOH those > are somewhat similar in the end). > > I'm going to push it when testing finishes but maybe there are some > testcases to adjust. > > PR tree-optimization/105679 > * tree-ssa-threadbackwards.cc > (back_threader_profitability::profitable_path_p): Avoid threading > when the entry edge is probably never executed. OK.   And more generally I'm absolutely OK with improving the costing heuristics. The one thing we need to keep in mind when adding this kind of check is that we may start seeing new diagnostics from the middle end -- while the path may not be profitable to thread from a performance standpoint, it may be useful to thread from a diagnostic standpoint. But I'd argue that for such cases we really want to move to a model where the predicate analysis bits are used consistently to prune away "can't happen" cases for middle end diagnostics rather than relying on threading to optimize away can't happen cold paths. Jeff