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 4F6733858D33 for ; Wed, 22 Feb 2023 12:16:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F6733858D33 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=1677068182; 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=Vp4OYUC7VNazITwkxNEf9YpBjWCb48XW9GkN3U4WjtU=; b=a1RhfXA+9+MOAaR9xmz3r4w50xw3eO0w3XFgLWtoadcIWGjpN9J1z5pdyVYTY6p2m9px6C nHMo0GACsPhD/zhrWkw2KIiBc2HM/ECV0P3lGUeG58hQABjrIGr3+TSuhmPFvK/4QxjZwg Y16jDoExMkUkDAd/jmxM3m3yjdokphE= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-280-ytwDIJkTMrKsvJiiT5ZoEA-1; Wed, 22 Feb 2023 07:16:20 -0500 X-MC-Unique: ytwDIJkTMrKsvJiiT5ZoEA-1 Received: by mail-lj1-f197.google.com with SMTP id m6-20020a2ea886000000b002959ba063f1so313602ljq.6 for ; Wed, 22 Feb 2023 04:16:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Vp4OYUC7VNazITwkxNEf9YpBjWCb48XW9GkN3U4WjtU=; b=Yv+XiQIN2347hw1f1XC5KAYr4ut3P3dsTxqyCXf2TlJYErduMqL1iIQrHBMuTCTOOX dfjyWSzsTrlRBOgH9YDRtYxkn5CzmHgPcxn9ELRHsbBfyD7w8rWZWMv1u4uzRymowQdf HD6NdQCB2b/QSGkCQr1gfOu8rjMYtNjleLzA5Z8eLuapMZ7GxFQTGbr2ZVVemWxc4V6c FoRG3RPKTmhfE4EzZgR0y+UFlkr1otgEPfxQic093UPbwPftf2E93C8QVPnm7VePxZpz NFX60nba6Tv6C/jAbqWJYmZEgwzY41yVaAM0djwakGFMYBirc0U79PDL6HwZV7ebEW3r fTsw== X-Gm-Message-State: AO0yUKWdxd0hHTj+NJqzn+Rfm93RdXDZtrUWDb4VULQf02RC3VkPLZn5 80vcJv/ZKxJ89K1TJD6j9FIPYot2LagC5Ywrbef/2lnSr+/zQb9qqLh9QnXIi4oQqglfFjgpMX2 RAZr8gW1bW0BQ918SmjBAcIKaFL5eovKqPQ== X-Received: by 2002:a05:651c:b9b:b0:295:942d:9b6 with SMTP id bg27-20020a05651c0b9b00b00295942d09b6mr1183851ljb.7.1677068179463; Wed, 22 Feb 2023 04:16:19 -0800 (PST) X-Google-Smtp-Source: AK7set/QBwl5HcmV2t7am8Rp0WTBIeQvUMlsFR5f3qtVBj0j1NbxUg7ACEIDwnONI34G+0bAhUJFGzl/+ebff+sXsxc= X-Received: by 2002:a05:651c:b9b:b0:295:942d:9b6 with SMTP id bg27-20020a05651c0b9b00b00295942d09b6mr1183846ljb.7.1677068179139; Wed, 22 Feb 2023 04:16:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Wed, 22 Feb 2023 12:16:07 +0000 Message-ID: Subject: Re: [PATCH] tree: Add 3 argument fndecl_built_in_p To: Richard Biener Cc: Jakub Jelinek , gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: On Wed, 22 Feb 2023 at 11:49, Richard Biener wrote: > > On Wed, 22 Feb 2023, Jakub Jelinek wrote: > > > On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote: > > > > The following testcase ICEs because we still have some spots that > > > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP > > > > the same. > > > > This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE) > > || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP)) > > a lot and from grepping around, we do something like that in lots of > > other places, or in some spots instead as > > (fndecl_built_in_p (node, BUILT_IN_NORMAL) > > && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1 > > || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2)) > > The following patch adds an overload for this case, so we can write > > it in a shorter way. It isn't worth for 3+, code in that case > > typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL) > > + switch in DECL_FUNCTION_CODE. > > > > If this isn't appropriate for GCC 13 (or not at all), I think we'll > > need to change at least ipa-prop.cc because it suffers from the same > > problem as the previous patch was fixing. > > Is it possible to use C++ (template) magic to expand the > 1 argument > case to > > if (fndecl_built_in_p (BUILT_IN_NORMA) > && (... || ... || ... > > lispy we'd expand to the head check and then recursively on the > first and the remaining args. In C++17 yes, there are fold expressions, so you'd write it as literally: if (fndecl_built_in_p (BUILT_IN_NORMA) && (DECL_FUNCTION_CODE (node) == name || ...) Where "name" is a parameter pack, and the "..." is literally what the code would contain, not an abbreviation for the example :-) For C++11 you can write it recursively. Something like: // Single argument case terminates recursion. inline bool fndecl_built_in_matches_name_p (const_tree node, built_in_function name1) { return DECL_FUNCTION_CODE (node) == name1; } // Recursive case. If names... is an empty pack then the overload above // is a better match. template inline bool fndecl_built_in_matches_name_p (const_tree node, built_in_function name1, Functions... names) { return DECL_FUNCTION_CODE (node) == name1 || fndecl_built_in_matches_name_p (node, names...); } // Call with one or more names. template inline bool fndecl_built_in_p (const_tree node, built_in_function name1, Functions names...) { return (fndecl_built_in_p (node, BUILT_IN_NORMAL) && fndecl_built_in_matches_name_p (node, name1, names...); } I think the "is a better match" comment is the status of C++ after a DR, so might not actually be true in C++11 with GCC 4.8, I can check that (and if needed, rewrite the recursive case to avoid the problem).