From patchwork Mon Nov 20 14:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 167149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2217473vqn; Mon, 20 Nov 2023 06:01:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTTGSleTiHCC4dWSs1F4IEKKX9ltbE1QRlqVhycZ9KHAiViI3wi+z8MkXmTrStQ517iQxF X-Received: by 2002:a05:620a:3184:b0:775:681d:dc06 with SMTP id bi4-20020a05620a318400b00775681ddc06mr9316546qkb.63.1700488884764; Mon, 20 Nov 2023 06:01:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700488884; cv=pass; d=google.com; s=arc-20160816; b=An7s4tjbLmOCK8PGwQC6sRfOCRebNDEVFH1qPvGnJTqr1v/bxqSLWMmUV+ujLf+/Y0 XESbLp0YBWifg0rdV1Rvi7gaj2jGV6d1ROzoQf38TC57WD7li6yiBIG8rz+cui5kN04E P7BcXMaUg6fmzaZ/WeryivUGK22j+tS7IdcxZijnZABA2RNojofwN9cVbp9ATvSsxWNs JuwjBL7q6DZXfn7TFrhJI2kJO4UE81Wfwv5vEOtmNeYdmTFn2/IULj/MDqhduZcZmBJh 0HnelN+z+h/APQP0sJqsvdp0wNRL1s/zwhoS5qwkC3qNgzkZ6j7GA6Gy1diiqSxi9IV7 y6fA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:to:from:date:dkim-signature:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=rFeeCCKZqf6zmuazScEMQ9wPQJ0rN8YqV8VBWmk8rq0=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=Nqy2g8l15L/Q99ZIJonsfvCvfmM/jD1+YtTh2S0PuWOfkqlqCJuEOgfSFwYTICPyOp 4oFcbhutYADN+Ya/T4DBrS+GNy4Zws2Mla409z0M/9V+F8NekObYxm1ZzA2jJiDcizkW WoIoVMIujj84oYEvH6UiXD3aF7LMa9vwPdtATSSHdFzfnaO9rqjgWrwPbNqTlP1k3Eym QImX4tZxByqwXwDO3Qih3nVFtvbz9WyHuZEfiiphr5/bVF61X5EOgq44mcmfnVm4WLlc jmSDldco7OZyP9/oBAktjNdLmTalq1R0q6MV6nLXT6Y6QW4FFi3FFtETIdSt77+oUHdC xkOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=heT4qA7Q; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y16-20020a05622a121000b004181ea65532si7542988qtx.80.2023.11.20.06.01.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 06:01:24 -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=@suse.de header.s=susede2_rsa header.b=heT4qA7Q; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 821F83890433 for ; Mon, 20 Nov 2023 14:01:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 63CA93841922 for ; Mon, 20 Nov 2023 14:00:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63CA93841922 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63CA93841922 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700488828; cv=none; b=VgTODwlxRPE+q1jt9q35ULS/Z26kv+Wz/nsRrrbAfCjWMaJqiAQthBTA6r7XSRlS2Ztsj6Cxk0+ovcEoYubCiq8Zdv6E1UuAX2NJyUAdJ5r6Fni+MTLluk8XjkN0gjneQRak+12Q5VphjBfsllH8EG4uYRAQQite1/6T3tqdE10= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700488828; c=relaxed/simple; bh=V+yE/35qZsftonKoWjHO2DjE1aB4M4zbmIlCI7gmKXw=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=x61ENS9wxuSJxB/ef1XIGPKlN2UcxX39174ZfquB8ExbnwzniJV50rmp2WouA6JVP881OH6q2EcI/VeLxvQiuJOLTg6zbCvhE2Uhi0B8r0uF4wYMWnB8f71sNaa9DVZ/mf//6YdEjSdYFpgcFUYKBMvdQP2yXA22Mo0XjOuOToU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4A47F218EA for ; Mon, 20 Nov 2023 14:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700488825; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=rFeeCCKZqf6zmuazScEMQ9wPQJ0rN8YqV8VBWmk8rq0=; b=heT4qA7QZTitb5kPPPhO57mPXcAMoq4aXlplZHDg8rGGZFYebpZ+5BzofVQS9a1ZYNwV8G DZaMrTbEUWscqlPQLLVcYRXYaV3yxliu10WGfKJ/EEiUj9J093wGRyGyGPPssTqJ9Gw3TO yUk2hJxC69AhIYtebFP9wMSZlC6T3YI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700488825; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=rFeeCCKZqf6zmuazScEMQ9wPQJ0rN8YqV8VBWmk8rq0=; b=I0mWlPf952Y2UhChl1B/XngtZwwmRsIO29VB5wB2h2BVSP7cKFydwnhw69td16z7eMz+Ei hUXa3qMBc+rzuZCA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 3AA9F2C48C for ; Mon, 20 Nov 2023 14:00:25 +0000 (UTC) Date: Mon, 20 Nov 2023 14:00:25 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/112622 - convert and vector-to-float User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spamd-Bar: ++++++++++++++++ Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=none; spf=softfail (smtp-out1.suse.de: 149.44.160.134 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de X-Rspamd-Server: rspamd1 X-Spamd-Result: default: False [16.49 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(-1.00)[149.44.160.134:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_DN_NONE(0.00)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; CLAM_VIRUS_FAIL(0.00)[failed to scan and retransmits exceed]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MX_GOOD(-0.01)[]; NEURAL_SPAM_LONG(3.50)[1.000]; DMARC_NA(1.20)[suse.de]; VIOLATED_DIRECT_SPF(3.50)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 16.49 X-Rspamd-Queue-Id: 4A47F218EA X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20231120140107.821F83890433@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783091833045019825 X-GMAIL-MSGID: 1783091833045019825 The following avoids ICEing when trying to convert a vector to a scalar float. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/112622 * convert.cc (convert_to_real_1): Use element_precision where a vector type might appear. Provide specific diagnostic for unexpected vector argument. * gcc.dg/pr112622.c: New testcase. --- gcc/convert.cc | 6 +++++- gcc/testsuite/gcc.dg/pr112622.c | 5 +++++ gcc/testsuite/gcc.dg/simd-2.c | 4 ++-- gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_1.c | 8 ++++---- gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c | 8 ++++---- 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr112622.c diff --git a/gcc/convert.cc b/gcc/convert.cc index ac6af7026a7..46c8bcb31f8 100644 --- a/gcc/convert.cc +++ b/gcc/convert.cc @@ -292,7 +292,7 @@ convert_to_real_1 (tree type, tree expr, bool fold_p) case NEGATE_EXPR: if (!flag_rounding_math && FLOAT_TYPE_P (itype) - && TYPE_PRECISION (type) < TYPE_PRECISION (itype)) + && element_precision (type) < element_precision (itype)) { tree arg = convert_to_real_1 (type, TREE_OPERAND (expr, 0), fold_p); @@ -334,6 +334,10 @@ convert_to_real_1 (tree type, tree expr, bool fold_p) error ("pointer value used where a floating-point was expected"); return error_mark_node; + case VECTOR_TYPE: + error ("vector value used where a floating-point was expected"); + return error_mark_node; + default: error ("aggregate value used where a floating-point was expected"); return error_mark_node; diff --git a/gcc/testsuite/gcc.dg/pr112622.c b/gcc/testsuite/gcc.dg/pr112622.c new file mode 100644 index 00000000000..c73587ced99 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr112622.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ + +typedef __attribute__((__vector_size__(4))) float V; + +V v = (float)-v; /* { dg-error "vector value used" } */ diff --git a/gcc/testsuite/gcc.dg/simd-2.c b/gcc/testsuite/gcc.dg/simd-2.c index d24e076218d..411bb49a5e1 100644 --- a/gcc/testsuite/gcc.dg/simd-2.c +++ b/gcc/testsuite/gcc.dg/simd-2.c @@ -33,10 +33,10 @@ hanneke () foo = a; /* { dg-error "incompatible types when assigning" } */ /* Casted assignment between scalar and SIMD of same size. */ - foo = (typeof (foo)) foo2; /* { dg-error "aggregate value used where a floating-point was expected" } */ + foo = (typeof (foo)) foo2; /* { dg-error "vector value used where a floating-point was expected" } */ /* Casted assignment between scalar and SIMD of different size. */ - foo1 = (typeof (foo1)) foo2; /* { dg-error "aggregate value used where a floating-point was expected" } */ + foo1 = (typeof (foo1)) foo2; /* { dg-error "vector value used where a floating-point was expected" } */ /* Operators on compatible SIMD types. */ a += b + b; diff --git a/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_1.c b/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_1.c index 8bc3f4a7b8f..5d19dcb7b6d 100644 --- a/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_1.c +++ b/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_1.c @@ -123,12 +123,12 @@ __m128bf16 footest (__m128bf16 vector0) (void) glob_bfloat_vec; (__m128bf16) glob_bfloat_vec; - (__bf16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ + (__bf16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ (short) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m128bf16' {aka '__vector\(8\) __bf16'} to type 'short int' which has different size} } */ (int) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m128bf16' {aka '__vector\(8\) __bf16'} to type 'int' which has different size} } */ - (_Float16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ - (float) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ - (double) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ + (_Float16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ + (float) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ + (double) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ (__v8si) glob_bfloat_vec; /* { dg-error {cannot convert a value of type '__m128bf16' {aka '__vector\(8\) __bf16'} to vector type '__vector\(8\) int' which has different size} } */ (__m256) glob_bfloat_vec; /* { dg-error {cannot convert a value of type '__m128bf16' {aka '__vector\(8\) __bf16'} to vector type '__vector\(8\) float' which has different size} } */ diff --git a/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c b/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c index 2a8a535daae..d4e6fc8cd23 100644 --- a/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c +++ b/gcc/testsuite/gcc.target/i386/vect-bfloat16-typecheck_2.c @@ -116,12 +116,12 @@ __m256bf16 footest (__m256bf16 vector0) (void) glob_bfloat_vec; (__m256bf16) glob_bfloat_vec; - (__bf16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ + (__bf16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ (short) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m256bf16' {aka '__vector\(16\) __bf16'} to type 'short int' which has different size} } */ (int) glob_bfloat_vec; /* { dg-error {cannot convert a vector of type '__m256bf16' {aka '__vector\(16\) __bf16'} to type 'int' which has different size} } */ - (_Float16) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ - (float) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ - (double) glob_bfloat_vec; /* { dg-error {aggregate value used where a floating-point was expected} } */ + (_Float16) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ + (float) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ + (double) glob_bfloat_vec; /* { dg-error {vector value used where a floating-point was expected} } */ (__v8si) glob_bfloat_vec; (__m256) glob_bfloat_vec;