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.129.124]) by sourceware.org (Postfix) with ESMTPS id 97CAF3858C56 for ; Wed, 19 Oct 2022 16:55:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 97CAF3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666198517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/SeLM+Lb/Lz9jcVXiHGoryv1TYzSML4yCyqsp45OqsA=; b=ZNkzwSBzVxfpx4JWp+YgPEgF3sPuYh1N3533LOhfSNenQxZyLqN/g3z1r/ZqCB8mQmXsRA c0p7dxZ+nPR0S7LqLHsGACf+VUP5llWDQnm7ZC0E4QXWIkbRxqXrr+wROMg3H/V54JY+En PY6jH8JiDgOmuEu0AfOVbyT5Dq4fhJo= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-499-EUjqFCHSNZeSScCZtWdWxA-1; Wed, 19 Oct 2022 12:55:15 -0400 X-MC-Unique: EUjqFCHSNZeSScCZtWdWxA-1 Received: by mail-io1-f71.google.com with SMTP id y4-20020a5e9204000000b006bbffbc3d27so13560497iop.5 for ; Wed, 19 Oct 2022 09:55:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=vAeHcxAR1jgQaJ7Jq09kIcxZCd2ba8OnfDsjtonWqY0=; b=E45MJALTVMnQcUIJEvZJO95GlM44KKmQAiRUoWTTTg1GaCf+vt0lM5MYuFtD+hsrJi 4SYSaMZQQSJFe9MADwWtQM9TdDvdB8sHmrGFI+eGfymVXJsYkbqqaEEy6vddobOcL8EU R8haWEFBvOVWtqvz8OOQH2qUGDrITQoca6Lc+LBZNJVT24z4sPRyoGMy0upa9VbH1lCf ogZZT9IJswnVA9oYXHEi9hIU76re+0V3t+k2vOHh7ucDbwXd/TynpWaZPaVtIuBvA/1g TReh1MNYpHp79///V2Kh8Mw2Wgs9394ujuukYfNQOXOm79lZDPEj194h47eWaMcHVc8o yWHQ== X-Gm-Message-State: ACrzQf1RT52bqYR/FSGUZIo8IWx7BNdZwGLICzoK8Lk/XGQlkhN2zLbZ MvQ9lKgTQD4qLRJlvZCKmo8a4szZJOVm9v7RymuG5tICZi3djRVD8AcLiUZqUqLS/4XB8uA+pQG 7xtPqm1bALbJA+FKHzw== X-Received: by 2002:a05:6602:1855:b0:6bc:40b9:676e with SMTP id d21-20020a056602185500b006bc40b9676emr6363714ioi.213.1666198514962; Wed, 19 Oct 2022 09:55:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4gMq/AElTMf0bcT7xDCgWFmnmIcj+Dd9BqffqIsLgwcNh16O9TaS7J2oP5EabNNohYZbWQwg== X-Received: by 2002:a05:6602:1855:b0:6bc:40b9:676e with SMTP id d21-20020a056602185500b006bc40b9676emr6363695ioi.213.1666198514638; Wed, 19 Oct 2022 09:55:14 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3c4d? ([2607:fea8:a263:f600::3c4d]) by smtp.gmail.com with ESMTPSA id z1-20020a056602204100b0068869b84b02sm2361958iod.21.2022.10.19.09.55.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Oct 2022 09:55:13 -0700 (PDT) Message-ID: <70311a20-1a94-21a1-e897-37289c9e0f0c@redhat.com> Date: Wed, 19 Oct 2022 12:55:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH] middle-end, v4: IFN_ASSUME support [PR106654] To: Jakub Jelinek Cc: Richard Biener , Jan Hubicka , gcc-patches@gcc.gnu.org, "hernandez, aldy" References: <479fa663-fb3e-a90d-ae7a-0fdd5acbfa00@redhat.com> <16da3b46-f061-076a-19b5-c482f45477b3@redhat.com> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="------------WQKnf8nKaMD6K2vFV3iHvEIV" Content-Language: en-US X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: This is a multi-part message in MIME format. --------------WQKnf8nKaMD6K2vFV3iHvEIV Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 10/19/22 12:06, Jakub Jelinek wrote: > Hi! > > On Tue, Oct 18, 2022 at 05:31:58PM -0400, Andrew MacLeod wrote: >> Anyway, gives you something to experiement with.   If you would find a >> different interface useful, let me know, or if there are limitations or >> other expansions we might need.   This seems like something reasonable for >> you to start working with? > Thanks for working on this. > >> + // Look for ASSUME calls, and call query_assume_call for each argument >> + // to determine if there is any inferred range to be had. >> + if (is_a (s) && gimple_call_internal_p (s) >> + && gimple_call_internal_fn (s) == IFN_ASSUME) >> + { >> + tree assume_id = gimple_call_arg (s, 0); >> + for (unsigned i = 1; i < gimple_call_num_args (s); i++) >> + { >> + tree op = gimple_call_arg (s, i); >> + tree type = TREE_TYPE (op); >> + if (gimple_range_ssa_p (op) && Value_Range::supports_type_p (type)) >> + { >> + Value_Range assume_range (type); >> + if (query_assume_call (assume_range, assume_id, op)) >> + { >> + add_range (op, assume_range); >> + if (dump_file) >> + { >> + print_generic_expr (dump_file, assume_id, TDF_SLIM); >> + fprintf (dump_file, " assume inferred range of "); >> + print_generic_expr (dump_file, op, TDF_SLIM); >> + fprintf (dump_file, " to "); >> + assume_range.dump (dump_file); >> + fputc ('\n', dump_file); >> + } >> + } > Not sure I understand this part. op is whatever we pass as the ith > argument to IFN_ASSUME. I'd expect that at this point one needs to > remap that to the (i-1)th PARM_DECL of assume_id (so e.g. when you > have the above loop you could as well start with DECL_ARGUMENTS and move > that to DECL_CHAIN at the end of every iteration. And then > query ssa_default_def (DECL_STRUCT_FUNCTION (assume_id), parm) > in each case and get global range of what that returns. OK, this is the bit of code I dont know how to write :-) yes, op is the name of the value within this current function, and yes, that needs to be mapped to the argument decl in the assume function.   Then we need to query what range was given to that name during the assume pass.  when that is returned, the add_range (op, range) will inject it as a side effect. Can you write that loop? > >> + for (unsigned x= 0; x < gimple_phi_num_args (phi); x++) > for (unsigned x = 0; ... > ? > >> @@ -4345,6 +4345,30 @@ execute_ranger_vrp (struct function *fun, bool warn_array_bounds_p) >> scev_initialize (); >> calculate_dominance_info (CDI_DOMINATORS); >> >> + assume_query *r2 = new assume_query (); >> + for (unsigned i = 0; i < num_ssa_names; i++) >> + { >> + tree name = ssa_name (i); >> + if (!name || !gimple_range_ssa_p (name)) >> + continue; >> + tree type = TREE_TYPE (name); >> + if (!Value_Range::supports_type_p (type)) >> + continue; >> + Value_Range assume_range (type); >> + if (r2->assume_range_p (assume_range, name)) >> + { >> + if (dump_file) >> + { >> + fprintf (dump_file, "for an assume function, "); >> + print_generic_expr (dump_file, name, TDF_SLIM); >> + fprintf (dump_file, " would have a range of "); >> + assume_range.dump (dump_file); >> + fputc ('\n', dump_file); >> + } >> + } >> + } >> + delete r2; > I have expected (but tell me if that isn't possible) this could be something > done in the new pass_assumptions::execute () rather than vrp and you'd > create the assume_query there (i.e. just for assume_functions) and then > query it solely for ssa_default_def of the parameters and save in > SSA_NAME_RANGE_INFO. I just discovered the assumption pass, and I have moved it to there. I dont know much about managing the parameters, but presumably yes, we'd only query it for the parameters...........  I was showing the query for every name just to show what its producing. As for storing it, SSA_NAME_RANGE_INFO is for the current function, that woud be easy.  if we store it there, how do we look up that range from another functi\on when we have the ASSUME_ID ? That was unclear to me., I've attached the replacement version of 0003* which uses the assume pass, and writes the global values out.  It still loops over all names at the moment Andrew > --------------WQKnf8nKaMD6K2vFV3iHvEIV Content-Type: text/x-patch; charset=UTF-8; name="0003-Show-output-in-assume-pass.patch" Content-Disposition: attachment; filename="0003-Show-output-in-assume-pass.patch" Content-Transfer-Encoding: base64 RnJvbSA2NTU2MjcxNDRiOGQ4YzAyODQyZDE1ZWM4M2Q3MjAxODAyMzE1NjRhIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBBbmRyZXcgTWFjTGVvZCA8YW1hY2xlb2RAcmVkaGF0LmNvbT4K RGF0ZTogTW9uLCAxNyBPY3QgMjAyMiAxMjoyODoyMSAtMDQwMApTdWJqZWN0OiBbUEFUQ0ggMy8z XSBTaG93IG91dHB1dCBpbiBhc3N1bWUgcGFzcwoKLS0tCiBnY2MvdHJlZS12cnAuY2MgfCAyOSAr KysrKysrKysrKysrKysrKysrKysrKysrKysrKwogMSBmaWxlIGNoYW5nZWQsIDI5IGluc2VydGlv bnMoKykKCmRpZmYgLS1naXQgYS9nY2MvdHJlZS12cnAuY2MgYi9nY2MvdHJlZS12cnAuY2MKaW5k ZXggMWFkYjE1Yzk5MzQuLjNlYzNkN2RhYTc0IDEwMDY0NAotLS0gYS9nY2MvdHJlZS12cnAuY2MK KysrIGIvZ2NjL3RyZWUtdnJwLmNjCkBAIC00NDY1LDYgKzQ0NjUsMzUgQEAgcHVibGljOgogICBi b29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