From patchwork Thu Mar 2 08:24:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 63270 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4114304wrd; Thu, 2 Mar 2023 00:25:49 -0800 (PST) X-Google-Smtp-Source: AK7set98+CiCOBp+o5MWAb+FGfdAYrPJ25s4vu4ATHP+OdX7bHQzU1N5tcKLQMy5aqZR58VBNOuY X-Received: by 2002:a17:907:a44:b0:8df:e176:483b with SMTP id be4-20020a1709070a4400b008dfe176483bmr12379138ejc.3.1677745549341; Thu, 02 Mar 2023 00:25:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677745549; cv=none; d=google.com; s=arc-20160816; b=NS9AOsXsFGCzkyH89FOmVlco2ojUThrcl2QxtsM0xoSvoMgFAEFCjTaLcDitEQ+CuQ KD6B6Phm8NgyLxJrWJXTH0E5BqfkiPTgPZ2gDwNmae2ZTaefE1GzroJPwy9wmZP/g0Ly oAIRb3iEfdBlilSCO/Xu9BzkFZsnb0dYCjvuXYd2komBGdMST64225NuDqsTuYd30klS 4R+v2NLX2nwMd45ORs936qIk5RAgVlIomPD31oFeVc0tsAipwnTUm2RUGaKgDDt7uq8L rB6aO27JU+9IHe1oP9oFnyLsAKbdGXPNrxzyTdA8jrRkjbbQ9k4UCgJTPkbHVGsV9F7o H76g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=lHFpeOJtWHnAYeBN75x7HiOyy1yZ/NZaawry9XM6Yxg=; b=rWbIPrNpBaZLKAEF2g+v/OUIBcOJi17f0ZQ5VF9PTqrS2UUGwXOmnXmtbhtTRjlA0N LJCTNgSZenSjP5ut8J2TYRBTdv334D6e3TKtXy9mgkM+LpO7lwL+touI5uvx03Tt8pDQ VQpGxk8mUp8V4GM4F7nDbQrHtGkaFxhTRJ2G0cT9hTclhe7YdF7CWlGpF2CBZ9dTdADn Wi7eQIsjMEcACynVrhGCrzHR9n/NW1j3OsaTt+VZ4drp8De4l3vspIgEgt4rXSqCS50M ZMhr5uWKgeyyIZh5Jfz3fnW5isBvbkPi/JbaXdBjO3T4m20UC4a1zti00/IHJunMJvqw ECNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IlCOW0Nd; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a21-20020a1709066d5500b008e01978a238si7769556ejt.52.2023.03.02.00.25.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 00:25:49 -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=@gcc.gnu.org header.s=default header.b=IlCOW0Nd; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5A10385840C for ; Thu, 2 Mar 2023 08:25:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5A10385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677745540; bh=lHFpeOJtWHnAYeBN75x7HiOyy1yZ/NZaawry9XM6Yxg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=IlCOW0NdEp892pV8kpDYTekG/0zoc5pZzXDvvGXHxrz4EWrSSznZvRWKyq4ssb0T4 H+S47gEJyet+64PcjNW9e1ahCmtMicT1JdbU+VlycWJ+h6ub46Ak+FJ4H9JZ2PEqY/ 6olGBWhYZoasfyMIP+1Jzq82gcgAWiNxF964pJxs= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id D8E9C3858D3C for ; Thu, 2 Mar 2023 08:24:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8E9C3858D3C 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-278-wY4KxYZ0OQK6I9EVwDJmvg-1; Thu, 02 Mar 2023 03:24:54 -0500 X-MC-Unique: wY4KxYZ0OQK6I9EVwDJmvg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC6DA185A78B; Thu, 2 Mar 2023 08:24:53 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CAB02026D4B; Thu, 2 Mar 2023 08:24:53 +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 3228OoFq3809063 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 2 Mar 2023 09:24:51 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3228OoYS3809061; Thu, 2 Mar 2023 09:24:50 +0100 Date: Thu, 2 Mar 2023 09:24:49 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] fold-const: Ignore padding bits in native_interpret_expr REAL_CST reverse verification [PR108934] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.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.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 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?1759243717341536165?= X-GMAIL-MSGID: =?utf-8?q?1759243717341536165?= Hi! In the following testcase we try to std::bit_cast a (pair of) integral value(s) which has some non-zero bits in the place of x86 long double (for 64-bit 16 byte type with 10 bytes actually loaded/stored by hw, for 32-bit 12 byte) and starting with my PR104522 change we reject that as native_interpret_expr fails on it. The PR104522 change extends what has been done before for MODE_COMPOSITE_P (but those don't have any padding bits) to all floating point types, because e.g. the exact x86 long double has various bit combinations we don't support, like pseudo-(denormals,infinities,NaNs) or unnormals. The HW handles some of those as exceptional cases and others similarly to the non-pseudo ones. But for the padding bits it actually doesn't load/store those bits at all, it loads/stores 10 bytes. So, I think we should exempt the padding bits from the reverse comparison (the native_encode_expr bits for the padding will be all zeros), which the following patch does. For bit_cast it is similar to e.g. ignoring padding bits if the destination is a structure which has padding bits in there. The change changed auto-init-4.c to how it has been behaving before the PR105259 change, where some more VCEs can be now done. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-02 Jakub Jelinek PR c++/108934 * fold-const.cc (native_interpret_expr) : Before memcmp comparison copy the bytes from ptr to a temporary buffer and clearing padding bits in there. * gcc.target/i386/auto-init-4.c: Revert PR105259 change. * g++.target/i386/pr108934.C: New test. Jakub --- gcc/fold-const.cc.jj 2023-01-04 10:52:43.124897826 +0100 +++ gcc/fold-const.cc 2023-03-01 16:49:14.531490482 +0100 @@ -8873,11 +8873,13 @@ native_interpret_expr (tree type, const valid values that GCC can't really represent accurately. See PR95450. Even for other modes, e.g. x86 XFmode can have some bit combinationations which GCC doesn't preserve. */ - unsigned char buf[24]; + unsigned char buf[24 * 2]; scalar_float_mode mode = SCALAR_FLOAT_TYPE_MODE (type); int total_bytes = GET_MODE_SIZE (mode); + memcpy (buf + 24, ptr, total_bytes); + clear_type_padding_in_mask (type, buf + 24); if (native_encode_expr (ret, buf, total_bytes, 0) != total_bytes - || memcmp (ptr, buf, total_bytes) != 0) + || memcmp (buf + 24, buf, total_bytes) != 0) return NULL_TREE; return ret; } --- gcc/testsuite/gcc.target/i386/auto-init-4.c.jj 2022-04-13 15:42:39.105365390 +0200 +++ gcc/testsuite/gcc.target/i386/auto-init-4.c 2023-03-02 08:56:53.788029181 +0100 @@ -15,6 +15,5 @@ long double foo() } -/* The long double init isn't expanded optimally, see PR105259. For ia32 - it uses zero-initialization. */ -/* { dg-final { scan-assembler-times "long\t-16843010" 3 } } */ +/* { dg-final { scan-assembler-times "long\t-16843010" 5  { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "long\t-16843010" 3  { target { ia32 } } } } */ --- gcc/testsuite/g++.target/i386/pr108934.C.jj 2023-03-01 17:04:19.931299866 +0100 +++ gcc/testsuite/g++.target/i386/pr108934.C 2023-03-01 17:03:27.567062785 +0100 @@ -0,0 +1,28 @@ +// PR c++/108934 +// { dg-do compile { target c++11 } } + +struct S { unsigned long long a[2]; }; +struct T { unsigned long long b[6]; }; +struct U { unsigned long long c[2]; long double d; unsigned long long e[2]; }; + +#if __SIZEOF_LONG_DOUBLE__ == 16 && __LDBL_MANT_DIG__ == 64 && __SIZEOF_LONG_LONG__ == 8 +constexpr long double +foo (S x) +{ + return __builtin_bit_cast (long double, x); +} + +constexpr S a = { 0ULL, 0xffffffffffff0000ULL }; +constexpr long double b = foo (a); +static_assert (b == 0.0L, ""); + +constexpr U +bar (T x) +{ + return __builtin_bit_cast (U, x); +} + +constexpr T c = { 0ULL, 0ULL, 0ULL, 0xffffffffffff0000ULL, 0ULL, 0ULL }; +constexpr U d = bar (c); +static_assert (d.d == 0.0L, ""); +#endif