From patchwork Mon Oct 24 07:19:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 8181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp299114wru; Mon, 24 Oct 2022 00:20:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5v1xakXoS8e42KFv9Vz24/gmxB0hZWVuLCKeLyALwX23yxtgH2sHHYCVyGfkmYYFpF729+ X-Received: by 2002:a17:907:72c7:b0:791:9ba2:4978 with SMTP id du7-20020a17090772c700b007919ba24978mr25303285ejc.217.1666596011299; Mon, 24 Oct 2022 00:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666596011; cv=none; d=google.com; s=arc-20160816; b=a9ohucEX9R5JN33pHz5/VQ+Q61TqcFG1xjUZSwx22SPffjIvsWvz0m/KGD+2zRuEJz ByW0nF9gg7Migrj6ad3fQO7m5rsqANNoIT+6OOclQwz9PIlEIOFCmIdrzQZuaLXID1nz NaM2ZDOdoQjV9kRT26FZLvtd/lkRaowP/KsZFOfHVgMHRswH8p5sQMyFOGk1L4N7oizf Cs9ursCJRJPMNtdCfb0IP0NuX3JqxaMOXYa66ruH+4jE8LBeV9Q6JEJKMLd1IquVkxKa N19PdPZv/nyiDg+vceuG0byg/JiVNArg2Git0DiQxbTLH9PZzsaUosmUSvQWZV2jySrJ zVrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/48I4fbjpVfPXYnyejqjwWsXg0/ktsHYVsUy0OZpLNI=; b=b/2iWUKl84jhP3M/YxkFuHAE5NOXQ7uRZrfVqLRhPSiFOmjj9yU7wfE0WZTfvERQJ6 5v0/LO3EZ1Ki0nBkv/YydN+DzRKqPSVv/PrsZST+7dgLn1Gom8Fe0REKQdLN+Sohs0/W eGD4i9bMn2yXiBvqF81bOUM0tgQQhMB3pycAAg3W4ag7UyoCRQ7xQgE2zn9wADoUDJ7X V7nO4JpAgcRnypXl8ZxtPNdXp/Fy41AYAvcItnaICNkcipAw22qMqC4iz5e2RJZKser1 MBqM7GOEvMKniBgLQh1CJmjCyTnL8/9VFF4vdw6ApfSk5MI7YDr7ZdLY0+p0bxuDdM6e /ayQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=N1rVC9ME; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x23-20020a170906135700b007470b52f94esi22466781ejb.199.2022.10.24.00.20.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 00:20:11 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=N1rVC9ME; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D88D3858025 for ; Mon, 24 Oct 2022 07:20:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D88D3858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666596010; bh=/48I4fbjpVfPXYnyejqjwWsXg0/ktsHYVsUy0OZpLNI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=N1rVC9MEPmmFlE0SBllfbdlhwtY71ropKstyG211lo8FBgPiXoh25G9649GKK6PyS ULVouJe3QHxlMhfXqtQN3mxd0ff4UCjeDn75spLtm9QW8pOCkRxpnm7qEyyv0oSChm y0RZ7/XFhbNK2WOu8kyk8D1Xh6514lYXuQkIkI7E= 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 0DB1238582A8 for ; Mon, 24 Oct 2022 07:19:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0DB1238582A8 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-463-XpxAw326OXCH1hVfJXYEGg-1; Mon, 24 Oct 2022 03:19:21 -0400 X-MC-Unique: XpxAw326OXCH1hVfJXYEGg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 819F4101A528; Mon, 24 Oct 2022 07:19:21 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 418DE49BB60; Mon, 24 Oct 2022 07:19:21 +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 29O7JIoZ3042766 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 24 Oct 2022 09:19:18 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29O7JH1u3042765; Mon, 24 Oct 2022 09:19:17 +0200 Date: Mon, 24 Oct 2022 09:19:17 +0200 To: "Joseph S. Myers" , Jason Merrill Subject: [PATCH] c, c++: Fix up excess precision handling of scalar_to_vector conversion [PR107358] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747552579274942805?= X-GMAIL-MSGID: =?utf-8?q?1747552579274942805?= Hi! As mentioned earlier in the C++ excess precision support mail, the following testcase is broken with excess precision both in C and C++ (though just in C++ it was triggered in real-world code). scalar_to_vector is called in both FEs after the excess precision promotions (or stripping of EXCESS_PRECISION_EXPR), so we can then get invalid diagnostics that say float vector + float involves truncation (on ia32 from long double to float). The following patch fixes that by calling scalar_to_vector on the operands before the excess precision promotions, let scalar_to_vector just do the diagnostics (it does e.g. fold_for_warn so it will fold EXCESS_PRECISION_EXPR around REAL_CST to constants etc.) but will then do the actual conversions using the excess precision promoted operands (so say if we have vector double + (float + float) we don't actually do vector double + (float) ((long double) float + (long double) float) but vector double + (double) ((long double) float + (long double) float) Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-10-24 Jakub Jelinek PR c++/107358 c/ * c-typeck.cc (build_binary_op): Pass operands before excess precision promotions to scalar_to_vector call. cp/ * typeck.cc (cp_build_binary_op): Pass operands before excess precision promotions to scalar_to_vector call. testsuite/ * c-c++-common/pr107358.c: New test. * g++.dg/cpp1y/pr68180.C: Remove -fexcess-precision=fast from dg-options. Jakub --- gcc/c/c-typeck.cc.jj 2022-10-14 09:35:56.199990261 +0200 +++ gcc/c/c-typeck.cc 2022-10-22 17:54:24.378839301 +0200 @@ -11995,8 +11995,8 @@ build_binary_op (location_t location, en if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE) || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE)) { - enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1, - true); + enum stv_conv convert_flag = scalar_to_vector (location, code, orig_op0, + orig_op1, true); switch (convert_flag) { --- gcc/cp/typeck.cc.jj 2022-10-20 13:54:22.535670240 +0200 +++ gcc/cp/typeck.cc 2022-10-22 17:56:58.589715301 +0200 @@ -5191,6 +5191,8 @@ cp_build_binary_op (const op_location_t orig_type0 = type0 = TREE_TYPE (op0); orig_type1 = type1 = TREE_TYPE (op1); + tree non_ep_op0 = op0; + tree non_ep_op1 = op1; /* The expression codes of the data types of the arguments tell us whether the arguments are integers, floating, pointers, etc. */ @@ -5303,8 +5305,9 @@ cp_build_binary_op (const op_location_t if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE) || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE)) { - enum stv_conv convert_flag = scalar_to_vector (location, code, op0, op1, - complain & tf_error); + enum stv_conv convert_flag + = scalar_to_vector (location, code, non_ep_op0, non_ep_op1, + complain & tf_error); switch (convert_flag) { --- gcc/testsuite/c-c++-common/pr107358.c.jj 2022-10-22 18:46:59.390375310 +0200 +++ gcc/testsuite/c-c++-common/pr107358.c 2022-10-22 18:01:52.973660719 +0200 @@ -0,0 +1,30 @@ +/* PR c++/107358 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fexcess-precision=standard" } */ + +typedef float __attribute__((vector_size (4 * sizeof (float)))) A; +typedef double __attribute__((vector_size (2 * sizeof (double)))) B; + +void +foo (A *x) +{ + *x = *x - 124.225514990f; +} + +void +bar (A *x, float y) +{ + *x = *x - y; +} + +void +baz (B *x) +{ + *x = *x + 124.225514990f; +} + +void +qux (B *x, double y) +{ + *x = *x + y; +} --- gcc/testsuite/g++.dg/cpp1y/pr68180.C.jj 2022-10-14 09:28:28.339159477 +0200 +++ gcc/testsuite/g++.dg/cpp1y/pr68180.C 2022-10-22 17:59:07.012946513 +0200 @@ -1,6 +1,6 @@ // PR c++/68180 // { dg-do compile { target c++14 } } -// { dg-additional-options "-Wno-psabi -fexcess-precision=fast" } +// { dg-additional-options "-Wno-psabi" } typedef float __attribute__( ( vector_size( 16 ) ) ) float32x4_t; constexpr float32x4_t fill(float x) {