From patchwork Sat Nov 11 08:22:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 164102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp112842vqg; Sat, 11 Nov 2023 00:23:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqABttwfOo49ORAue5EtvclQvkqQBaTKiug/8OeJOye5k+yLJw7HPvOeZFkCswnn2IHp3N X-Received: by 2002:a05:620a:44d2:b0:76f:2f7b:cf61 with SMTP id y18-20020a05620a44d200b0076f2f7bcf61mr2021657qkp.61.1699691014198; Sat, 11 Nov 2023 00:23:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699691014; cv=pass; d=google.com; s=arc-20160816; b=0UPQ5QM/9VfTlayoySUTHdqHa2ZY2Ii387kjM4R+4QeMT7brHh/DnYFs3Alc2oOR/G /Oh0ZilaMkl3hYm0c+bGCAMVuz3Mc3ufZ2DzJMB8AOwUMFurplsQLOCR+DsTta0so4QL RNc8NIGwkv6cR53l800Cr+2pZHheO6NYvetG72/yK8+6P8ndNpi1U9CHczmBGzKMfsLX Y+FNa8HW5zRD+u4qJFpSGBZpTCbfvJwpHHmDd/lG+w7caiUWGx6lCihUb5IDccbm5hdI vzZb4iZZ2b/t3Bvf9Iq7uPyDTv2iJodnxI905LnH5aZHtyTg3vjetHVYrYd6ViO58naS d+hA== 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 :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=a4hcvBLY2bcVRkik+BA+BBIR0AeU2/Z64qdta9ppw7k=; fh=XKd5Dae4Q+m40qQXNLLQi5OG3iLYpiypWclTQ6VA9Xk=; b=hNhW3T9nHpe8x3trl1kFonhFpG4NvAdyMb10v9xJ6uYjxPQxPMoEmZnIHMk3AxzfJc oe1dgQiD2JQK/Drw4MJbuvM0aO6Uj6Zgk3Fhw6EzkKhRCVwrvpIS/zZZbYEcMB7xIx8B bmojHZ9iA9mLOeuCASC0hhnga7WZDfv6aTErowgp7WodohoWoRwlPaoT7etmyzlC2AP7 hilvuE3lGfhufP6FXvUiYKsRR4jKju+L5GbW6JxPSj7aEWhKkKh3N7mK32E2pGLY/Ph0 KL565FzDKm9iSndb6mLIbrklU9DQO0/kq5uboI2AMgxYOPIGN/zJ/ztxhG4Nf3KVCGPh HVWw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BH4z8pK8; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb5-20020a05620a650500b007759c22e907si1105662qkn.142.2023.11.11.00.23.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 00:23:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BH4z8pK8; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 F29653858D1E for ; Sat, 11 Nov 2023 08:23:33 +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 EA4333858D1E for ; Sat, 11 Nov 2023 08:23:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA4333858D1E 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 EA4333858D1E 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=1699690988; cv=none; b=q83MAbR0S+bfFwYyW6/UHcXD3qRDWeOVZ95gk8sQiBHBFY5PxE8IHApQJHzoG4kGwDM/KU7HKvgvPYDdzweZLdl7X/5KlehUUhVV1b73y+EG7HX4NI+8DekyIDYFKH+6pUGYCOwnWTC3qa2DRmUr9LOHtFgTlQI26gQauK5X5ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699690988; c=relaxed/simple; bh=0Tjntfr56AEpDsTp3pqrNNDnZhA+nwKmWFISK75ELCI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=WRVrr3aZxeOCVLRfpDqkuwqha3/VlVm3W0dHxaZkXt7fQrlocBAQANSD3eOGp73C/8ltfYq7Wk81rTdGhRJ7ss/abDJtkRJ/vjJPdP9zrwma65HyoEnGs45H1ki6hI4dcx8fuxF+uJRZlnaXSOzcX9pt2vC3vOmZfMxBgySQJPA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699690986; 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; bh=a4hcvBLY2bcVRkik+BA+BBIR0AeU2/Z64qdta9ppw7k=; b=BH4z8pK814d4rds6OKLTdIZUQ72+kyjxOmYtn5zAGxR8Ou2QzocLXjK7+QN87JHHU9Es6m Fqf9zQ32qydbL6tVVeTjpAdpOGfr8KfcRVIoIk3Jdlr5Xlun30qRj3epIike41LDtnpfG8 uQG2f3h7K6XfQ/VGFDYG1b8F3/BPEhA= 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-395-NEVz-yJdOny6UHZdyTqDlQ-1; Sat, 11 Nov 2023 03:23:02 -0500 X-MC-Unique: NEVz-yJdOny6UHZdyTqDlQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 F3D9880B633; Sat, 11 Nov 2023 08:23:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6AF41C060AE; Sat, 11 Nov 2023 08:23:01 +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 3AB8MxD03773530 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 11 Nov 2023 09:22:59 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AB8MwJ63773529; Sat, 11 Nov 2023 09:22:58 +0100 Date: Sat, 11 Nov 2023 09:22:58 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c, c++: Add new value for vector types for __builtin_classify_type (type) Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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: 1782255204885618916 X-GMAIL-MSGID: 1782255204885618916 Hi! 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? 2023-11-11 Jakub Jelinek gcc/ * typeclass.h (enum type_class): Add vector_type_class. * builtins.h (type_to_class): Add FOR_TYPE argument. * builtins.cc (type_to_class): Add FOR_TYPE argument, for VECTOR_TYPE return vector_type_class if it is true, no_type_class otherwise. (expand_builtin_classify_type, fold_builtin_classify_type): Pass false to type_to_class second argument. gcc/c/ * c-parser.cc (c_parser_postfix_expression_after_primary): Pass true to type_to_class second argument. gcc/cp/ * parser.cc (cp_parser_postfix_expression): Pass true to type_to_class second argument. * pt.cc (tsubst_expr): Likewise. 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.h.jj 2023-09-29 10:39:37.073836032 +0200 +++ gcc/builtins.h 2023-11-10 11:17:22.196907216 +0100 @@ -156,6 +156,6 @@ extern internal_fn associated_internal_f extern internal_fn replacement_internal_fn (gcall *); extern bool builtin_with_linkage_p (tree); -extern int type_to_class (tree); +extern int type_to_class (tree, bool); #endif /* GCC_BUILTINS_H */ --- gcc/builtins.cc.jj 2023-11-09 09:17:40.230182483 +0100 +++ gcc/builtins.cc 2023-11-10 11:19:29.669129855 +0100 @@ -1833,10 +1833,11 @@ expand_builtin_return (rtx result) expand_naked_return (); } -/* Used by expand_builtin_classify_type and fold_builtin_classify_type. */ +/* Used by expand_builtin_classify_type and fold_builtin_classify_type. + FOR_TYPE is true for __builtin_classify_type (type), false otherwise. */ int -type_to_class (tree type) +type_to_class (tree type, bool for_type) { switch (TREE_CODE (type)) { @@ -1859,6 +1860,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 for_type ? vector_type_class : no_type_class; default: return no_type_class; } } @@ -1869,7 +1871,7 @@ static rtx expand_builtin_classify_type (tree exp) { if (call_expr_nargs (exp)) - return GEN_INT (type_to_class (TREE_TYPE (CALL_EXPR_ARG (exp, 0)))); + return GEN_INT (type_to_class (TREE_TYPE (CALL_EXPR_ARG (exp, 0)), false)); return GEN_INT (no_type_class); } @@ -8678,7 +8680,8 @@ fold_builtin_classify_type (tree arg) if (arg == 0) return build_int_cst (integer_type_node, no_type_class); - return build_int_cst (integer_type_node, type_to_class (TREE_TYPE (arg))); + return build_int_cst (integer_type_node, + type_to_class (TREE_TYPE (arg), false)); } /* Fold a call EXPR (which may be null) to __builtin_strlen with argument --- gcc/c/c-parser.cc.jj 2023-11-09 09:04:18.473545429 +0100 +++ gcc/c/c-parser.cc 2023-11-10 11:19:57.907735925 +0100 @@ -12249,7 +12249,7 @@ c_parser_postfix_expression_after_primar &ret.expr_const_operands); parens.skip_until_found_close (parser); expr.value = build_int_cst (integer_type_node, - type_to_class (ret.spec)); + type_to_class (ret.spec, true)); break; } else --- gcc/cp/parser.cc.jj 2023-11-09 09:04:18.771541207 +0100 +++ gcc/cp/parser.cc 2023-11-10 11:20:24.732360518 +0100 @@ -7974,11 +7974,9 @@ cp_parser_postfix_expression (cp_parser TREE_TYPE (postfix_expression) = integer_type_node; } else - { - postfix_expression - = build_int_cst (integer_type_node, - type_to_class (type)); - } + postfix_expression + = build_int_cst (integer_type_node, + type_to_class (type, true)); break; } } --- gcc/cp/pt.cc.jj 2023-11-04 09:02:35.456000422 +0100 +++ gcc/cp/pt.cc 2023-11-10 11:20:42.783107902 +0100 @@ -20434,7 +20434,8 @@ tsubst_expr (tree t, tree args, tsubst_f TREE_TYPE (ret) = integer_type_node; } else - ret = build_int_cst (integer_type_node, type_to_class (type)); + ret = build_int_cst (integer_type_node, + type_to_class (type, true)); RETURN (ret); } else if (koenig_p --- 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) != -1) + abort (); + if (__builtin_classify_type (vf) != -1) + abort (); }