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 F3C433858D33 for ; Wed, 22 Feb 2023 12:35:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3C433858D33 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=1677069338; 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=91+gFyV6sFVWwYEzmprEJgwU6hHwCW/av5F0TAxHSRI=; b=Qq19DiAZMsubNSB2eLNQzDk8g60wF/F7qugoOappfKHm8Ws8M38BU6DVLXGRoMamrCXV2m o1jt9eI8oys7mofAJhUZ8hT9n6zrSyWBJW5OSOZkmzHB/WE0U8p6jm2F5y4TcpTMWgfrtl ZjSgB6D11lRsNzSQnN2AZxxg17uW4CY= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-253-yIf0b6goPkWTxqMQnA69Bg-1; Wed, 22 Feb 2023 07:35:37 -0500 X-MC-Unique: yIf0b6goPkWTxqMQnA69Bg-1 Received: by mail-lf1-f72.google.com with SMTP id a11-20020a195f4b000000b004b53d7241f6so2353091lfj.4 for ; Wed, 22 Feb 2023 04:35:37 -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=91+gFyV6sFVWwYEzmprEJgwU6hHwCW/av5F0TAxHSRI=; b=5BqDbhGm8+OuULJ6jtELnOl3/oqPKKMM2hMSJjD/0GSF5pxsAzSIKA/Iuv5j7kAKnQ zggNHd9bmh3A8JrOMXSFJ7A5YHolgOmA8h9kedyz0saAdqrrtAmbObsJZq8FfvnYz6np +g5bCLCknF6b6uTjxidmHLcdbfriQPJflLm1o/gQhsRrprN4r8/BkMT3ZARr3mxEPFhO 2u5elypFLr6TTM9+UxGQ5i5O7JP3ZemWE6dVKH6443fyessIQq8QFfGCRFwIFgf5mift uNoeBRUhcF5eam1WQxIktobpUt8Bo9RrsBZEhVXUnPpp30EWZp3OGOdZEicNS64O2lxp 2AVA== X-Gm-Message-State: AO0yUKUDSjgk0S0Cqw4aqdi3V8YahJMdbimx9XUAmJByXnzilUDZ8rHz oC+1DMautHwCvju+E40KLxgr0ZA5A/Tk0gWqj0jtzFsg299CrjVhJWDjzatOoD5xs4PtEX6yjKG KnCZJlCzM/MxPE4tSZvF29h+ZETujv+mz/A== X-Received: by 2002:a05:6512:4cc:b0:4db:3ab7:79ca with SMTP id w12-20020a05651204cc00b004db3ab779camr2733746lfq.8.1677069335846; Wed, 22 Feb 2023 04:35:35 -0800 (PST) X-Google-Smtp-Source: AK7set/WsvGbPHt+72OUzXUZqBxajfrk1oOQZ+TJfZRVu0wrSKyh1Rw8+bC+pG09T6/noQaBV776Pf7RdCw94Q6W++U= X-Received: by 2002:a05:6512:4cc:b0:4db:3ab7:79ca with SMTP id w12-20020a05651204cc00b004db3ab779camr2733742lfq.8.1677069335545; Wed, 22 Feb 2023 04:35:35 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Wed, 22 Feb 2023 12:35:24 +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.1 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 12:16, Jonathan Wakely wrote: > > 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). Yes, I was right, it doesn't work in gcc 4.8. This does though (with typos above fixed too, and actually tested on GCC 4.8.5): // 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 for two or more names. template inline bool fndecl_built_in_matches_name_p (const_tree node, built_in_function name1, built_in_function name2, Functions... names) { return DECL_FUNCTION_CODE (node) == name1 || fndecl_built_in_matches_name_p (node, name2, 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...); } The variadic template fndecl_builtin_p above can replace the existing one in gcc/tree.h and will work for all the existing cases with a single name argument, but also support multiple names.