From patchwork Fri May 7 19:03:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1475653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=fEC8aQDG; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcKbf0nFXz9sVb for ; Sat, 8 May 2021 05:03:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47E143896827; Fri, 7 May 2021 19:03:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47E143896827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620414202; bh=DpBK8DNwFpQuhbDVJf/MhWVFWThZQ2FB5qGyCbpO+x4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fEC8aQDGYa41QUrrTcpeX0OK2BSQ2uwTr1Zolkr2b5beG6/NFAYe5A8OYHUcDGXg3 g7xgW90ObSFlZ0qAr/PFyWWvuScV0o0MPHzH+D9XmA6rwxGHWEJIaymFy6hZ/ClYM0 ssYQobf27V940VQMDI/9eY1fwi3uDQ1W/P3l0Eag= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 704443896826 for ; Fri, 7 May 2021 19:03:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 704443896826 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-502-Olwt2kH8MhKpBxGu9D1ArA-1; Fri, 07 May 2021 15:03:16 -0400 X-MC-Unique: Olwt2kH8MhKpBxGu9D1ArA-1 Received: by mail-qv1-f70.google.com with SMTP id y18-20020a0cd9920000b02901c32e3e18f7so7337515qvj.15 for ; Fri, 07 May 2021 12:03:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:cc:message-id:date:user-agent :mime-version:content-language; bh=DpBK8DNwFpQuhbDVJf/MhWVFWThZQ2FB5qGyCbpO+x4=; b=e8ys44cmmyE+HEoEtP8yDBPQpuDlbHeHK46oN3Yc61lkmCLbM1cPEv/BcmshOrizS6 98rqd6Mjy+GqLYuhwHc8qrb2B2YhnkDxOrawZ9DhDDScU8Pkw1nZlbC7u+6qQ3EuIhDk lGLYb8zlMEkZo7AyCMFB/L7p+05ijKKFarZkLHK3gVMX00Qtn+r3UpgvytNJjm28zut8 3h1MC9hDUC/APSMLKWktC6ASak9kCsFldqWWo8NxG7Nq8Y02SF2eknUATzIv9uTIwoHA yKOsLTeuJZpuV8wiqeVKA8EJEflQhAiFKx6vZDBLCmA9M69qT/2R/PlA749Vhj2oD8Q1 /99Q== X-Gm-Message-State: AOAM533eehclBsGeSu6fYAoc//5Clgc1wlhIYbmD5ZScP47fNqOOZent Y5jFUr5sbZZZUDAi5AKb6iHarWBoYeRpmHXDpT+1+S3ZQYjaXykFuuywRv+vSM8ggnMEIZnocCM aFZH1HUd4JjEX41WFuw== X-Received: by 2002:a05:622a:1394:: with SMTP id o20mr10979488qtk.92.1620414196388; Fri, 07 May 2021 12:03:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmZeU4Vc34hjo8sD7qFQkVJB+RknE8bv/Y7/D6yoGrtiFqA0xdlUReygluK0ATPdTdv+MLqw== X-Received: by 2002:a05:622a:1394:: with SMTP id o20mr10979472qtk.92.1620414196185; Fri, 07 May 2021 12:03:16 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25f:fa00:6ae8:97ac:cf69:b86d? ([2607:fea8:a25f:fa00:6ae8:97ac:cf69:b86d]) by smtp.gmail.com with ESMTPSA id g64sm5447359qkf.41.2021.05.07.12.03.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 May 2021 12:03:15 -0700 (PDT) To: gcc-patches Subject: [PATCH] tweak range-on-exit. Message-ID: Date: Fri, 7 May 2021 15:03:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Range on exit was not ding the right thing when a basic block contained no statements other than a PHI node. Rather than returning the value of the PHI, it was instead asking for range-on-entry for the phi, which  would trigger a walk back to the top of the CFG looking for the definition. When it didnt find it, it would then default to the global-value calculation. So it ended up with the right value, but it does a lot of unnecessary work and put entries in the on-entry cache that don't need to be there. Bootstraps on  x86_64-pc-linux-gnu with no testsuite regressions. Pushed. Andrew commit c0c25d1052950cecbf4488b7f76d41952672414a Author: Andrew MacLeod Date: Mon Apr 26 19:23:25 2021 -0400 Fix range_on_exit for PHI stmts when there are no other stmts in the block. last_stmt(bb) returns NULL for blocks which only have PHI stmts, and range_on_exit would trigger a cache fill all the way to the top of the program for the SSA_NAME. * gimple-range.cc (gimple_ranger::range_on_exit): Handle block with only PHI nodes better. diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 6158a754dd6..e94bb355de3 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -1003,14 +1003,23 @@ gimple_ranger::range_on_exit (irange &r, basic_block bb, tree name) gcc_checking_assert (bb != EXIT_BLOCK_PTR_FOR_FN (cfun)); gcc_checking_assert (gimple_range_ssa_p (name)); - gimple *s = last_stmt (bb); - // If there is no statement in the block and this isn't the entry - // block, go get the range_on_entry for this block. For the entry - // block, a NULL stmt will return the global value for NAME. - if (!s && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)) - range_on_entry (r, bb, name); - else + gimple *s = SSA_NAME_DEF_STMT (name); + basic_block def_bb = gimple_bb (s); + // If this is not the definition block, get the range on the last stmt in + // the block... if there is one. + if (def_bb != bb) + s = last_stmt (bb); + // If there is no statement provided, get the range_on_entry for this block. + if (s) range_of_expr (r, name, s); + else + { + range_on_entry (r, bb, name); + // See if there was a deref in this block, if applicable + if (!cfun->can_throw_non_call_exceptions && r.varying_p () && + m_cache.m_non_null.non_null_deref_p (name, bb)) + r = range_nonzero (TREE_TYPE (name)); + } gcc_checking_assert (r.undefined_p () || range_compatible_p (r.type (), TREE_TYPE (name))); }