From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 317BA3858D3C for ; Wed, 8 Dec 2021 21:06:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 317BA3858D3C Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-394-WoCAAF66NpqFGyCc8uf6RQ-1; Wed, 08 Dec 2021 16:06:24 -0500 X-MC-Unique: WoCAAF66NpqFGyCc8uf6RQ-1 Received: by mail-qt1-f199.google.com with SMTP id e2-20020ac84142000000b002b4bc4ffc49so5448445qtm.8 for ; Wed, 08 Dec 2021 13:06:24 -0800 (PST) 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:cc:references:from:in-reply-to :content-transfer-encoding; bh=z5wT6OJ0RzKZCIa9edKxDib9XViuB8F6lCFdk7w+MSU=; b=CF4HaUZ8kbwz24vGB+xiGMPeISYMr0E01mfz7KIZXA8UncdxV/eXo9qcCJghTZvnD5 A4w7TFl51qs59c4R23aq51a8dKu4o0nh93SABZtpEuAAC7mh7ef1HlkBYdFWnhumJlqo yj2bqNBSOlbXxxO9sGjvlr31HOIv2z4G41i1/v22YOwUrTSCy6m9CYLYQ278g9Xn6K5C YNM4XVFq80yzFbWhVzGl+gwYuECrHTU1ON5Wf3w/pOmDHQNFmd9U6SomWXnC95UDdrKW QR9azm41Z+h+Zbqa77JKKhi/H3Lt02Nxam7TEfOPlUYWlb8DYz/2gSSDyNFJXy3g9zt8 LZVA== X-Gm-Message-State: AOAM530CAw5kvReb4PVtg9gdTE+c356IoVguAmkRdkjJNLSjmUKQwpNo nx+miDzXnPzvF0CaKJBGg1EX5KrDHLXhW5DA8fbrJ9/fH5BXMlmnEyoEsFLerklUoa/PANhZzF7 XgCwzhOoDQEz9v7DPEA== X-Received: by 2002:ac8:7f4f:: with SMTP id g15mr11223010qtk.309.1638997582463; Wed, 08 Dec 2021 13:06:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNCS6Khrk73ZRyRQ45zM+R6/42rBj1zSZBrqs3PzZUdhwupnyn6oMnCZpmja3EU5UaW4Greg== X-Received: by 2002:ac8:7f4f:: with SMTP id g15mr11222901qtk.309.1638997581685; Wed, 08 Dec 2021 13:06:21 -0800 (PST) Received: from ?IPV6:2607:fea8:a262:5f00::a0bd? ([2607:fea8:a262:5f00::a0bd]) by smtp.gmail.com with ESMTPSA id m20sm2170747qkp.112.2021.12.08.13.06.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Dec 2021 13:06:21 -0800 (PST) Message-ID: <9528ce23-69b7-9994-5349-a0c6f83c92ae@redhat.com> Date: Wed, 8 Dec 2021 16:06:20 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH] Loop unswitching: support gswitch statements. To: Richard Biener , =?UTF-8?Q?Martin_Li=c5=a1ka?= Cc: GCC Patches , Aldy Hernandez , Andrew MacLeod References: <7bcc368c-3f26-4503-aec1-a3d6378e33ec@suse.cz> <561a3ffd-8973-d771-418f-76c484085cc5@suse.cz> <20265d97-6350-c234-695d-bc18e2e617b4@suse.cz> <1169b649-e3e2-36c9-f964-0b0ecd2530fa@suse.cz> <33509887-dfa3-6bb0-6fbe-cec8873f651f@suse.cz> <1423649f-7ef6-7408-36dc-4865f458b45e@redhat.com> <8f32d550-124c-9ed6-0ba1-a190a3f46ef0@suse.cz> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Wed, 08 Dec 2021 21:06:29 -0000 On 12/2/21 08:46, Richard Biener wrote: > On Thu, Dec 2, 2021 at 2:10 PM Martin Liška wrote: >> On 12/2/21 13:01, Richard Biener wrote: >>> On Thu, Dec 2, 2021 at 12:45 PM Martin Liška wrote: >>>> On 12/1/21 19:21, Andrew MacLeod wrote: >>>>> On 12/1/21 09:48, Martin Liška wrote: >>>>>> On 12/1/21 15:34, Richard Biener wrote: >>>>>>> On Wed, Dec 1, 2021 at 3:25 PM Martin Liška wrote: >>>>>>>> On 12/1/21 15:19, Richard Biener wrote: >>>>>>>>> which is compute the range of 'lhs' on edge_true into predicate->true_range, >>>>>>>>> assign that same range to ->false_range and then invert it to get the >>>>>>>>> range on the false_edge. What I am saying is that for better precision >>>>>>>>> you should do >>>>>>>>> >>>>>>>>> ranger->range_on_edge (predicate->false_range, edge_false, lhs); >>>>>>>>> >>>>>>>>> rather than prematurely optimize this to the inversion of the true range >>>>>>>>> since yes, ranger is CFG sensitive and only the_last_ predicate on a >>>>>>>>> long CFG path is actually inverted. >>>>>>>>> >>>>>>>>> What am I missing? >>>>>>>> I might be misunderstood, but I think it's the problem defined here: >>>>>>>> https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584605.html >>>>>>>> >>>>>>>> where I used the ranger->range_on_edge on the false_edge. >>>>>>> Ah, OK. But then even the true_edge range is possibly wrong, no? >>>>>> You are of course correct, I've just proved that in debugger :// >>>>>> >>>>>>> Consider >>>>>>> >>>>>>> for (;;) >>>>>>> { >>>>>>> if (a < 100) >>>>>>> if (a > 50) // unswitch on this >>>>>>> /* .. */ >>>>>>> if (a < 120) >>>>>>> /* ... */ >>>>>>> } >>>>>>> >>>>>>> then you record [51, 99] for true_range of the a > 50 predicate and thus >>>>>>> simplification will simplify the if (a < 120) check, no? >>>>>> Yep. >>>>>> >>>>>>> You can only record the range from the (CFG independent) a > 50 check, >>>>>>> thus [51, +INF] but of course at simplification time you can also use >>>>>>> the CFG context at each simplification location. >>>>>> @Andrew: How can I easily get irange based just on a stmt? Something like fold_range >>>>>> with int_range_max as the 3rd argument? >>>>>> >>>>> Sorry, I miss these things if I'm not directly CC'd a lot :-) >>>>> >>>>> So you just want to know the basic range the stmt generates without context? Sure, what you say would be fine, but your want to initialize it to the type range: >>>> Yes, I want to know range of LHS in a gcond statement and the same for cases in a gswitch statement. >>>> >>>>> int_range_max range (TREE_TYPE (name)); >>>>> >>>>> you can also simply trigger it using the current SSA_NAME_RANGE_INFO global values query instead of the default current contextual one... which , if there isnt a global range, will automatically use the range of the type of the argument.. so maybe just try >>>>> >>>>> fold_range (r, stmt, get_global_range_query ()) >>>> Doing >>>> >>>> predicate->true_range = int_range_max (TREE_TYPE (lhs)); >>>> fold_range (predicate->true_range, stmt, get_global_range_query ()); >>>> predicate->true_range.debug(); >>>> >>>> gives me _Bool VARYING. >>> Likely because that gives a range for the bool result rather than >>> a range for the LHS of a LHS op RHS on the true or false edge. >> Yes :) I guess Andrew can help us. > some grepping and poking found be gimple_range_calc_op1 which should > eventually do the trick (for constant gimple_cond_rhs at least). > Wait, didn't the  gori()->outgoing_edge_range_p()  call do this for you? Its a more general API that invokes gimple_range_calc_op1() under the covers. Im going to add myself to the cc so I don't miss any more of these :-) Or am I just way behind in my non-addressed reading? and that did address your issue? :-) Andrew