From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by sourceware.org (Postfix) with ESMTPS id 729613857BB2 for ; Mon, 23 Oct 2023 17:13:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 729613857BB2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.washington.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.washington.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 729613857BB2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::e2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698081185; cv=none; b=Qlr/15jBJ2AluIinWS4Hnl1qbW6df5zpM+/SVh/OTnna7Np0os9Tg6v2z703j3qNNw/DJMsmcpwl3Ao42J6nkmEcpJjMty9PLiARSPVnHH4ljjFByuJNjCZihPqu5Cw+nzFGE1hMYtthVVn6CkEVq0VsgZw4Y7peYrQav3uhMNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698081185; c=relaxed/simple; bh=34gGxiqrBNPkUib8lw0l8ezgOnzgxujPlS0zs0n0S80=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=G3fLunU7MSoqlkSrrWis32pWhOSc66J4W1ttTk+JU6ZXp2VsLLVQTJh21aIcXC3CZUzyIdc3RUhJ5+PFAjkqXU3eS5Y1WnHXFt1RHf4+We/K8HkvdpsjeBm4L5TEmq7RXa+wnlcqgYGK6BZB5VVCJAB1VUdtahh/J5ju/ddAiX8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-457bac7c3f5so1460513137.2 for ; Mon, 23 Oct 2023 10:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1698081181; x=1698685981; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+YPqIAoWzAtHOi67SEr2HAMOl/ukt9h4zhITLmR97Kc=; b=UquDlFSZj7PuuTZosPIFkqaPGKCBV3i5eL2dkhblRrZTSIwE2GM/h4XistAyYdxWn2 osLZcRtm+LPJcnwTxb9Sr6nit89CPvvSYRmQnSipT+ifp8+r4qLndNmcuogfDLrgV9HD 7R3ATagQtstjtHqZS0cRmLdne5P5mJXML4gxo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698081181; x=1698685981; 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=+YPqIAoWzAtHOi67SEr2HAMOl/ukt9h4zhITLmR97Kc=; b=NEUIncvqQjY1kW/xAjoAW9rzlth6+WRik2c/6vWeYsMOh72xv2xV3YK0tYYGPKHS9B 2CoZ6gAcBZIkUhpHGxq42GC2kzvLBzWeTYfb6yENjm5rFx6ctrSGvBd7V8MoUODmW2Zk ernq+yEg90JKHbcMgr33tDOFg8faKN9jFzClPeIOCU1L1SBoGywgUDKir1wBTaVpHGPs h6fj9ZtTxTFfSCPuPCy9x8iUieYE2ltfFKiBAtlILZQyJprDyrgtfkL/EdPUn5PU88lg a/ltnTj5jsRLwdPBSkqPNhXhS+F3QNR3O/4Oc6QAoTsSSH9bF06fUNRwAYyNVqi5truu UH5g== X-Gm-Message-State: AOJu0Yz4ZgQsYu8iJEoE9ypcueD0MYy/50ybKt3wEuVaJCpCCWDc8Tl4 T92heJr9ADiy6BgdlJJd+/G5+GPGNedvDJqXani2Zg== X-Google-Smtp-Source: AGHT+IEZJAMdr8BZ/u+wEt00ELS9pr6vKvvev9Zw39CVZZJrnTZh7do+JHL5BRC4QcE0+WHio20HxK4LOMCgVrohgUE= X-Received: by 2002:a67:ef4a:0:b0:457:e44d:c624 with SMTP id k10-20020a67ef4a000000b00457e44dc624mr9847920vsr.2.1698081181668; Mon, 23 Oct 2023 10:13:01 -0700 (PDT) MIME-Version: 1.0 References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-32-kmatsui@gcc.gnu.org> In-Reply-To: From: Ken Matsui Date: Mon, 23 Oct 2023 10:12:51 -0700 Message-ID: Subject: Re: [PATCH v23 31/33] libstdc++: Optimize std::is_pointer compilation performance To: Patrick Palka Cc: Jonathan Wakely , Ken Matsui , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000a234e7060865553a" X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000a234e7060865553a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Oct 23, 2023 at 10:00=E2=80=AFAM Patrick Palka = wrote: > On Sun, 22 Oct 2023, Ken Matsui wrote: > > > Hi Patrick, > > > > There is an issue with the code in > > libstdc++-v3/include/bits/cpp_type_traits.h. Specifically, Clang 16 > > does not accept the code, while Clang 17 does. Given that we aim to > > support the last two versions of Clang, we need to ensure that Clang > > 16 accepts this code. Can you please advise on the best course of > > action regarding this matter? > > The following workaround seems to make Clang happy: > > #include > > template > struct __is_pointer : std::bool_constant { }; > Ooh, this makes sense. Thank you! > > > > https://godbolt.org/z/PbxhYcb7q > > > > Sincerely, > > Ken Matsui > > > > On Fri, Oct 20, 2023 at 7:12=E2=80=AFAM Ken Matsui wrote: > > > > > > This patch optimizes the compilation performance of std::is_pointer > > > by dispatching to the new __is_pointer built-in trait. > > > > > > libstdc++-v3/ChangeLog: > > > > > > * include/bits/cpp_type_traits.h (__is_pointer): Use > __is_pointer > > > built-in trait. > > > * include/std/type_traits (is_pointer): Likewise. Optimize its > > > implementation. > > > (is_pointer_v): Likewise. > > > > > > Co-authored-by: Jonathan Wakely > > > Signed-off-by: Ken Matsui > > > --- > > > libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ > > > libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++--= -- > > > 2 files changed, 44 insertions(+), 8 deletions(-) > > > > > > diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h > b/libstdc++-v3/include/bits/cpp_type_traits.h > > > index 4312f32a4e0..246f2cc0b17 100644 > > > --- a/libstdc++-v3/include/bits/cpp_type_traits.h > > > +++ b/libstdc++-v3/include/bits/cpp_type_traits.h > > > @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) > > > // > > > // Pointer types > > > // > > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > > > + template > > > + struct __is_pointer : __truth_type<__is_pointer(_Tp)> > > > + { > > > + enum { __value =3D __is_pointer(_Tp) }; > > > + }; > > > +#else > > > template > > > struct __is_pointer > > > { > > > @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) > > > enum { __value =3D 1 }; > > > typedef __true_type __type; > > > }; > > > +#endif > > > > > > // > > > // An arithmetic type is an integer type or a floating point type > > > diff --git a/libstdc++-v3/include/std/type_traits > b/libstdc++-v3/include/std/type_traits > > > index 0641ecfdf2b..75a94cb8d7e 100644 > > > --- a/libstdc++-v3/include/std/type_traits > > > +++ b/libstdc++-v3/include/std/type_traits > > > @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > > : public true_type { }; > > > #endif > > > > > > - template > > > - struct __is_pointer_helper > > > + /// is_pointer > > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > > > + template > > > + struct is_pointer > > > + : public __bool_constant<__is_pointer(_Tp)> > > > + { }; > > > +#else > > > + template > > > + struct is_pointer > > > : public false_type { }; > > > > > > template > > > - struct __is_pointer_helper<_Tp*> > > > + struct is_pointer<_Tp*> > > > : public true_type { }; > > > > > > - /// is_pointer > > > template > > > - struct is_pointer > > > - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type > > > - { }; > > > + struct is_pointer<_Tp* const> > > > + : public true_type { }; > > > + > > > + template > > > + struct is_pointer<_Tp* volatile> > > > + : public true_type { }; > > > + > > > + template > > > + struct is_pointer<_Tp* const volatile> > > > + : public true_type { }; > > > +#endif > > > > > > /// is_lvalue_reference > > > template > > > @@ -3252,8 +3266,22 @@ template > > > inline constexpr bool is_array_v<_Tp[_Num]> =3D true; > > > #endif > > > > > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) > > > +template > > > + inline constexpr bool is_pointer_v =3D __is_pointer(_Tp); > > > +#else > > > template > > > - inline constexpr bool is_pointer_v =3D is_pointer<_Tp>::value; > > > + inline constexpr bool is_pointer_v =3D false; > > > +template > > > + inline constexpr bool is_pointer_v<_Tp*> =3D true; > > > +template > > > + inline constexpr bool is_pointer_v<_Tp* const> =3D true; > > > +template > > > + inline constexpr bool is_pointer_v<_Tp* volatile> =3D true; > > > +template > > > + inline constexpr bool is_pointer_v<_Tp* const volatile> =3D true; > > > +#endif > > > + > > > template > > > inline constexpr bool is_lvalue_reference_v =3D false; > > > template > > > -- > > > 2.42.0 > > > > > > > --000000000000a234e7060865553a--