From patchwork Tue Sep 28 09:33:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 45496 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 028F13858437 for ; Tue, 28 Sep 2021 09:33:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 028F13858437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632821628; bh=i5ggbG98YT5yBIjcJ4jhPekL8efC9vHoQSZi0EA2S8o=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=K4Bp935QzdwVj/ZajniXLh3yonIGZO7BC4ruUcM+CDu3Uzup5Bxh4UZS0hoDOk3ji n3egatAqgkv2daf9fQAWPZ/ECb0M22qP3KqzFV0238tPz0B92A71KbfG6j6NgmdPz0 MGmky40u35UBNOIDy7msTRqiG2pKscnUrVb8996s= 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 ESMTP id 39B733858C2C for ; Tue, 28 Sep 2021 09:33:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 39B733858C2C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-9Iz025onPEyq5O4fRuR8ZA-1; Tue, 28 Sep 2021 05:33:16 -0400 X-MC-Unique: 9Iz025onPEyq5O4fRuR8ZA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BAC81802936; Tue, 28 Sep 2021 09:33:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5652C5C1B4; Tue, 28 Sep 2021 09:33:15 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 18S9XCir3198038 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Sep 2021 11:33:13 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 18S9XCuo3198037; Tue, 28 Sep 2021 11:33:12 +0200 Date: Tue, 28 Sep 2021 11:33:12 +0200 To: Uros Bizjak Subject: [PATCH] i386: Don't emit fldpi etc. if -frounding-math [PR102498] Message-ID: <20210928093312.GV304296@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! i387 has instructions to store some transcedental numbers into the top of stack. The problem is that what exact bit in the last place one gets for those depends on the current rounding mode, the CPU knows the number with slightly higher precision. The compiler assumes rounding to nearest when comparing them against constants in the IL, but at runtime the rounding can be different and so some of these depending on rounding mode and the constant could be 1 ulp higher or smaller than expected. We only support changing the rounding mode at runtime if the non-default -frounding-mode option is used, so the following patch just disables using those constants if that flag is on. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-09-28 Jakub Jelinek PR target/102498 * config/i386/i386.c (standard_80387_constant_p): Don't recognize special 80387 instruction XFmode constants if flag_rounding_math. * gcc.target/i386/pr102498.c: New test. Jakub --- gcc/config/i386/i386.c.jj 2021-09-18 09:44:31.720743823 +0200 +++ gcc/config/i386/i386.c 2021-09-27 16:55:37.928072249 +0200 @@ -5035,7 +5035,8 @@ standard_80387_constant_p (rtx x) /* For XFmode constants, try to find a special 80387 instruction when optimizing for size or on those CPUs that benefit from them. */ if (mode == XFmode - && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS)) + && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS) + && !flag_rounding_math) { int i; --- gcc/testsuite/gcc.target/i386/pr102498.c.jj 2021-09-27 17:09:30.387509264 +0200 +++ gcc/testsuite/gcc.target/i386/pr102498.c 2021-09-27 17:09:22.548618148 +0200 @@ -0,0 +1,59 @@ +/* PR target/102498 */ +/* { dg-do run { target fenv } } */ +/* { dg-options "-frounding-math" } */ + +#include +#include + +__attribute__((noipa)) long double +fldlg2 (void) +{ + return 0.3010299956639811952256464283594894482L; +} + +__attribute__((noipa)) long double +fldln2 (void) +{ + return 0.6931471805599453094286904741849753009L; +} + +__attribute__((noipa)) long double +fldl2e (void) +{ + return 1.4426950408889634073876517827983434472L; +} + +__attribute__((noipa)) long double +fldl2t (void) +{ + return 3.3219280948873623478083405569094566090L; +} + +__attribute__((noipa)) long double +fldpi (void) +{ + return 3.1415926535897932385128089594061862044L; +} + +int +main () +{ + long double a = fldlg2 (); + long double b = fldln2 (); + long double c = fldl2e (); + long double d = fldl2t (); + long double e = fldpi (); + static int f[] = { FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD }; + int i; + for (i = 0; i < 4; i++) + { + fesetround (f[i]); + if (a != fldlg2 () + || b != fldln2 () + || c != fldl2e () + || d != fldl2t () + || e != fldpi ()) + abort (); + } + return 0; +}