From patchwork Fri Nov 17 14:04:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 166183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp548585vqn; Fri, 17 Nov 2023 06:04:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHclZma7NcZF5IQhCCamSgJ4Fx9ss/7bFwHUzUOb6u2l/UO3cPdjWD9MCFhQP9wdO3QR7ZB X-Received: by 2002:ac8:5bc1:0:b0:41c:cad6:7c4a with SMTP id b1-20020ac85bc1000000b0041ccad67c4amr13018793qtb.55.1700229884707; Fri, 17 Nov 2023 06:04:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700229884; cv=pass; d=google.com; s=arc-20160816; b=YukMyW/D5OyXnCjZ6rrP2/i1/81qCDYKGQnjHYuqcQ4FQ9wbHurNnQGJSx603toTkV UnEFz0SXHTP/Us+c2bu0WTvXI3/i/ZvJquzptJku1NutjWTQQPSf5Ngn8MablqEClWwb wHgTy74L+kpjcBfDjRPuGq9447XAWvj3pytm/bz2rME51mf0t2CdV9MnJcrD/RcOkoKX ShRT1D/jeUlsGwYHVMKsXWc3+UpFPsKdDiTyS77AKjs6IYARj4YetOYVRMIwiR4+DuGx nv2kTxYx3SrtqBZw1ZgvJK2CDhb9QYvtItARDQlWeUNz/8wlGJ3H4ta+4LSRgaiP9UH6 my5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=+87aK3elFD0weUIXhe7/AlOX/5If/MYkKO/TZ2VRebE=; fh=6Nt7jCkFgo5h5seMQWpx56o1dQ02AYpyA2k4X8ckn1U=; b=KoHTfRbkvnFK/ReagFo+5WBHqQdgooety2HsJ/0SoBXa+PeX6hrAUeIPsUKmGxJJoA Dcl0OM4sXHnt+a7RCygTORXDqcEO0hsWootpcmyXk6GlfR8LhsyS7C5FcYB23q0ratJS 1/TYSb+9IR/Esz7DVtV+T9cypT3Q7+ynnxeEtGP3y7OUPHVNd9TeUBYYHuqC88P4MQLj j7VTcuQWp1YIRwqPe73lbnZWFX1QkNU1PMTj1/+YRMp7aBrv/fWQpj9Sdm4sJyh0XCUZ 9DPdBkTt4tfpT2ftUoN5bJ6Gq9sZwy/Vy8RiPJGwDUiBzdpSCl7rLtEfBoZKNb87gXvU EAPw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AIOk5tTJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m19-20020a05622a119300b004181c16dfb8si1705805qtk.221.2023.11.17.06.04.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 06:04:44 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AIOk5tTJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B9C53858428 for ; Fri, 17 Nov 2023 14:04:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 E03F93858D1E for ; Fri, 17 Nov 2023 14:04:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E03F93858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E03F93858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700229862; cv=none; b=uEZ2gs9zfC/nG1oJxaETH1nU+0mksceW3z4htuFNbIduEwuHnBAuYNPKWHx9IJI/oNy8Aj90dQdVccgUtBiaROfiXeqvteM+l8sk88srFKcp26q3Jau5p+CIN7PNT+r6gO7HZUy02nquPAk/exPMLO59KVjNEh7XrocS8sMPcWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700229862; c=relaxed/simple; bh=D9VK5xdVl4nJ8SsEt6pn6WXkS2z7vwb9YBDN/VREY0A=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=gJUw15sMss61HqwJnF+u6/lXI8knGCfSjzctCdO0ELfBB2384bvv9/8wzxTz+35DDts0DwWfuAiL8188d1Ulg/vgwB+tWnaDRSak4fJVbbpZQIx4RFtq1XtPvEPjjaz/v8vbhgM3isbIGE9CqKyzTpiW/D57EyRfY33nU0FUqNA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700229860; h=from:from:reply-to: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=+87aK3elFD0weUIXhe7/AlOX/5If/MYkKO/TZ2VRebE=; b=AIOk5tTJZT8vrJ3so77vncrcg0n8jUXl7yYVy46JUUnSs5Y37fW6mkOtongTY/tWCm77lp kaYR+dPtcWRHHtMUZsDAdijKgOlbOcCMmD/DreIT8XHkSqfRM2OXkviYa9khmtu4EzKLBL gKIlTOUJOBnue6zCE9raWVgUR04i2hE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-yrsp1xhJObKxiu7Pp-fLbA-1; Fri, 17 Nov 2023 09:04:17 -0500 X-MC-Unique: yrsp1xhJObKxiu7Pp-fLbA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08E1E811000; Fri, 17 Nov 2023 14:04:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFCBC2026D4C; Fri, 17 Nov 2023 14:04:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AHE4E513135344 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Nov 2023 15:04:14 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AHE4Cs93135341; Fri, 17 Nov 2023 15:04:12 +0100 Date: Fri, 17 Nov 2023 15:04:12 +0100 From: Jakub Jelinek To: Joseph Myers , Jason Merrill , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end, v2: Add new value for vector types for __builtin_classify_type Message-ID: References: <788ba79-04d-f041-3bea-9172e33cd66@codesourcery.com> MIME-Version: 1.0 In-Reply-To: <788ba79-04d-f041-3bea-9172e33cd66@codesourcery.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782820251549392663 X-GMAIL-MSGID: 1782820251549392663 On Thu, Nov 16, 2023 at 11:49:03PM +0000, Joseph Myers wrote: > > > While filing a clang request to return 18 on _BitInts for > > > __builtin_classify_type instead of -1 they return currently, I've > > > noticed that we return -1 for vector types. I'm not convinced it is a good > > > idea to change behavior of __builtin_classify_type (vector_expression) > > > after 22 years it behaved one way (returned -1), but the > > > __builtin_classify_type (type) form is a new extension added for GCC 14, > > > so this patch returns 19 for vectors just in that second form. Many other > > > return values are only accessible from the second form as well (mostly > > > because > > > of argument promotions), so I think it is fine like that. > > > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > > > The C++ changes are OK (and obvious). I'm skeptical of the choice to keep > > returning -1 for the expression form, it seems more likely to cause problems > > (due to it disagreeing with the type form) than changing it (due to old code > > somehow relying on -1?). But people who are more familiar with the use of > > __builtin_classify_type should make the call. > > I'm also doubtful of keeping returning -1 for vectors in expression form > (I'd be surprised if people are actually using __builtin_classify_type > with vectors). The C changes are OK (but the front-end changes wouldn't > be needed at all if the vector and type argument cases aren't > distinguished). Given that you've both agreed that you think changing __builtin_classify_type (vector_expr) is ok (hopefully in the wild people test bct against known values rather than pretending to know what the unknown -1 means because it can mean multiple type kinds), here is a simpler patch which changes it even for that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-17 Jakub Jelinek gcc/ * typeclass.h (enum type_class): Add vector_type_class. * builtins.cc (type_to_class): Return vector_type_class for VECTOR_TYPE. gcc/testsuite/ * c-c++-common/builtin-classify-type-1.c (main): Add tests for vector types. Jakub --- gcc/typeclass.h.jj 2023-09-06 17:28:24.238977355 +0200 +++ gcc/typeclass.h 2023-11-10 10:50:59.519007647 +0100 @@ -38,7 +38,7 @@ enum type_class record_type_class, union_type_class, array_type_class, string_type_class, lang_type_class, opaque_type_class, - bitint_type_class + bitint_type_class, vector_type_class }; #endif /* GCC_TYPECLASS_H */ --- gcc/builtins.cc.jj 2023-11-09 09:17:40.230182483 +0100 +++ gcc/builtins.cc 2023-11-10 11:19:29.669129855 +0100 @@ -1859,6 +1859,7 @@ type_to_class (tree type) case LANG_TYPE: return lang_type_class; case OPAQUE_TYPE: return opaque_type_class; case BITINT_TYPE: return bitint_type_class; + case VECTOR_TYPE: return vector_type_class; default: return no_type_class; } } --- gcc/testsuite/c-c++-common/builtin-classify-type-1.c.jj 2023-09-26 09:25:30.019599039 +0200 +++ gcc/testsuite/c-c++-common/builtin-classify-type-1.c 2023-11-10 11:02:01.927776922 +0100 @@ -22,6 +22,10 @@ main () const char *p = (const char *) 0; float f = 0.0; _Complex double c = 0.0; + typedef int VI __attribute__((vector_size (4 * sizeof (int)))); + typedef float VF __attribute__((vector_size (4 * sizeof (int)))); + VI vi = { 0, 0, 0, 0 }; + VF vf = { 0.0f, 0.0f, 0.0f, 0.0f }; #ifdef __cplusplus struct T { void foo (); }; int &r = a[0]; @@ -43,6 +47,8 @@ main () static_assert (__builtin_classify_type (struct S) == 12, ""); static_assert (__builtin_classify_type (union U) == 13, ""); static_assert (__builtin_classify_type (int [2]) == 14, ""); + static_assert (__builtin_classify_type (VI) == 19, ""); + static_assert (__builtin_classify_type (VF) == 19, ""); static_assert (__builtin_classify_type (__typeof__ (a[0])) == 1, ""); static_assert (__builtin_classify_type (__typeof__ (e)) == 3, ""); static_assert (__builtin_classify_type (__typeof__ (b)) == 4, ""); @@ -57,6 +63,8 @@ main () static_assert (__builtin_classify_type (__typeof__ (s)) == 12, ""); static_assert (__builtin_classify_type (__typeof__ (u)) == 13, ""); static_assert (__builtin_classify_type (__typeof__ (a)) == 14, ""); + static_assert (__builtin_classify_type (__typeof__ (vi)) == 19, ""); + static_assert (__builtin_classify_type (__typeof__ (vf)) == 19, ""); #ifndef __cplusplus static_assert (__builtin_classify_type (a[0]) == 1, ""); static_assert (__builtin_classify_type (e) == 1, ""); @@ -102,4 +110,8 @@ main () abort (); if (__builtin_classify_type (a) != 5) abort (); + if (__builtin_classify_type (vi) != 19) + abort (); + if (__builtin_classify_type (vf) != 19) + abort (); }