From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 6A80E3857C52 for ; Thu, 21 Oct 2021 13:43:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A80E3857C52 Received: by mail-pj1-x1029.google.com with SMTP id q2-20020a17090a2e0200b001a0fd4efd49so5805674pjd.1 for ; Thu, 21 Oct 2021 06:43:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=7HQP9EgjGyZdhZj3yhG6u3n2ACBGibGCSqmjZWGaxf8=; b=2Na3J+YJZMAOJMqIzZ5+wLh+umTDt2sgsq6t90XF/NOLSQSyHvhphOUTYkTgFgqRBA EoJjGa9OyoyUKhjPkoY4YS85xOQ6Jfhj/EyEGZq5W9UxxjyTCFTlojb0A9KOWY0MXdqx K/4aAzr4PWkQ9tIPg2KTFT9SFNJixJQPz6B+pihTUjBo/4BSTEepq2AR/hAhthIaCRv6 LJUD9CTNWSMN0ZOPoVxDTK7VrOIV5IVK3ae4NA27mgmY7U3wXlAZcaAnF+oofIipkYKb Il5jrrf4z3yRS3ZnE0TysGqwSGHsiaETXOAjO7J6qLgItLckGVqmq/caSDfPAsm0mWxJ S9XQ== X-Gm-Message-State: AOAM533mGCeiGNVc//7pH4JofEhuMwxqBGEALXpj4xBxtiUml8rbPrEv NIqJeFqj7VBv9PHC2YfSzgE= X-Google-Smtp-Source: ABdhPJxUdOB976kwBZDhBOTjh2sMrtPPp+afa+F8zvincbn1lNOxnliOyPz/vHX+YThQlaLDU8EKMw== X-Received: by 2002:a17:90a:8b89:: with SMTP id z9mr6751479pjn.89.1634823832319; Thu, 21 Oct 2021 06:43:52 -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 u5sm7106805pfg.211.2021.10.21.06.43.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Oct 2021 06:43:52 -0700 (PDT) Subject: Re: [PATCH] Convert strlen pass from evrp to ranger. To: Aldy Hernandez , Richard Biener Cc: Jakub Jelinek , GCC patches , Andrew MacLeod References: <20211008151222.37790-1-aldyh@redhat.com> <49371bdc-edd7-a5fa-4d75-9b2ed51478ad@gmail.com> <88f397a8-78d1-fe74-c221-e846072edff1@redhat.com> <49b035a6-7160-07d9-0c34-4accdebc1af4@gmail.com> From: Jeff Law Message-ID: Date: Thu, 21 Oct 2021 07:43:50 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-3.9 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.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: Thu, 21 Oct 2021 13:43:54 -0000 On 10/21/2021 6:56 AM, Aldy Hernandez wrote: > On Thu, Oct 21, 2021 at 12:20 PM Richard Biener > wrote: >> On Wed, Oct 20, 2021 at 10:58 PM Jeff Law wrote: >>> >>> >>> On 10/18/2021 2:17 AM, Aldy Hernandez wrote: >>>> >>>> On 10/18/21 12:52 AM, Jeff Law wrote: >>>>> >>>>> On 10/8/2021 9:12 AM, Aldy Hernandez via Gcc-patches wrote: >>>>>> The following patch converts the strlen pass from evrp to ranger, >>>>>> leaving DOM as the last remaining user. >>>>> So is there any reason why we can't convert DOM as well? DOM's use >>>>> of EVRP is pretty limited. You've mentioned FP bits before, but my >>>>> recollection is those are not part of the EVRP analysis DOM uses. >>>>> Hell, give me a little guidance and I'll do the work... >>>> Not only will I take you up on that offer, but I can provide 90% of >>>> the work. Here be dragons, though (well, for me, maybe not for you ;-)). >>>> >>>> DOM is actually an evrp pass at -O1 in disguise. The reason it really >>>> is a covert evrp pass is because: >>>> >>>> a) It calls extract_range_from_stmt on each statement. >>>> >>>> b) It folds conditionals with simplify_using_ranges. >>>> >>>> c) But most importantly, it exports discovered ranges when it's done >>>> (evrp_range_analyzer(true)). >>>> >>>> If you look at the evrp pass, you'll notice that that's basically what >>>> it does, albeit with the substitute and fold engine, which also calls >>>> gimple fold plus other goodies. >>>> >>>> But I could argue that we've made DOM into an evrp pass without >>>> noticing. The last item (c) is particularly invasive because these >>>> exported ranges show up in other passes unexpectedly. For instance, I >>>> saw an RTL pass at -O1 miss an optimization because it was dependent >>>> on some global range being set. IMO, DOM should not export global >>>> ranges it discovered during its walk (do one thing and do it well), >>>> but I leave it to you experts to pontificate. >>> All true. But I don't think we've got many, if any, hard dependencies >>> on those behaviors. >>> >>>> The attached patch is rather trivial. It's mostly deleting state. It >>>> seems DOM spends a lot of time massaging the IL so that it can fold >>>> conditionals or thread paths. None of this is needed, because the >>>> ranger can do all of this. Well, except floats, but... >>> Massaging the IL should only take two forms IIRC. >>> >>> First, if we have a simplification we can do. That could be const/copy >>> propagation, replacing an expression with an SSA_NAME or constant and >>> the like. It doesn't massage the IL just to massage the IL. >>> >>> Second, we do temporarily copy propagate the current known values of an >>> SSA name into use points and then see if that allows us to determine if >>> a statement is already in the hash tables. But we undo that so that >>> nobody should see that temporary change in state. >> Are you sure we still do that? I can't find it at least. > I couldn't either, but perhaps what Jeff is referring to is the ad-hoc > copy propagation that happens in the DOM's use of the threader: > > /* Make a copy of the uses & vuses into USES_COPY, then cprop into > the operands. */ > FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES) > { > tree tmp = NULL; > tree use = USE_FROM_PTR (use_p); > > copy[i++] = use; > if (TREE_CODE (use) == SSA_NAME) > tmp = SSA_NAME_VALUE (use); > if (tmp) > SET_USE (use_p, tmp); > } > > cached_lhs = simplifier->simplify (stmt, stmt, bb, this); > > /* Restore the statement's original uses/defs. */ > i = 0; > FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_ALL_USES) > SET_USE (use_p, copy[i++]); Exactly what I was referring to.  It may be worth an experiment -- I can't recall when this code went in.  It might be a remnant from the original threader that pre-dates block copying.  In that world we had to look up expressions in the table as part of the step to verify that we could safely ignore statements at the start of a block. Or it could be something that was added to improve threading when the condition we're trying to thread through is partially redundant on the thread path.  This would allow us to discover that partial redundancy and exploit it for threading. In either case this code may have outlived its usefulness.  I wonder what would happen if we just took it out. jeff