From patchwork Sun Apr 19 12:19:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1272855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tu0vUQYw; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 494pn11jyrz9sPF for ; Sun, 19 Apr 2020 22:20:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55016385DC35; Sun, 19 Apr 2020 12:20:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55016385DC35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587298800; bh=yYKgY9/QAvJXZWswY/60QKhkYuHrPYwKtRiRb2liFgU=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tu0vUQYwe3MHho3cObcuC/2hJ/j+59McHoanBHuK2FnFXx8oQoNgP6VbHV8Xgyi8E DWmhHkQ4zHLTe1BuAQxoiA8Jj3v0v0Fi7FAtUvwXNUbEDE0cMzhtu+Zolly1O0ystI btWr5tUu1HU/KUESKBuQWUAbUCe36nP4JtC1epS0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id D65493858D31 for ; Sun, 19 Apr 2020 12:19:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D65493858D31 Received: by mail-il1-x131.google.com with SMTP id i16so2014448ils.12 for ; Sun, 19 Apr 2020 05:19:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=yYKgY9/QAvJXZWswY/60QKhkYuHrPYwKtRiRb2liFgU=; b=sLiAY3L4cWjxhwDkcmlWP6HQmXj36UuoiSUemcixW4eDQvaC0YLHJbFAIu6APPTC4X wUtrObOQvHyfDy9VdhASTIopTmq0tUoQgvWoKveIk++mQnuXTNs02XTYHTxxwBgCZp36 Mvhm+2PNMw/myu0MTGFVt2wmPFE2wbKPk4BA2EONBl/9VQhQWGTF/LCPD9S7SUbbE2He 2ZurED2JpICAJdbLjMIvfRh+pIs2OXpZff9Y+IoaC7szB1Y8fUc4qnesRKuJ5cFewkSr FJI+W98HImHpYGpBEnmNk3ICYCNvJB4lUORBSVjDME1/Jm97kpZgjFMr9o6R60cTen8u H7Ag== X-Gm-Message-State: AGi0PuaJVY5t/JOfxZhtG6F1+6H/C/45q9UFgjbGUq88aH85RSASBwRf 586NPJ+GX/YxTtL66jn0GJf1EVEsptybhLhJLL23FDxYnuc= X-Google-Smtp-Source: APiQypJ4Ru3TnDfwVUdaHI2gdTWqgxXNubJjqgjq8oLtePhPZhd31d184UTam9H8ul7WTvcud4cCA44n9332m7N9d98= X-Received: by 2002:a92:d211:: with SMTP id y17mr11477761ily.254.1587298796024; Sun, 19 Apr 2020 05:19:56 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 19 Apr 2020 14:19:44 +0200 Message-ID: Subject: [committed] i386: Remove unneeded assignments when triggering SSE exceptions To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-20.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Uros Bizjak via Gcc-patches From: Uros Bizjak Reply-To: Uros Bizjak Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" According to "Intel 64 and IA32 Arch SDM, Vol. 3: "Because SIMD floating-point exceptions are precise and occur immediately, the situation does not arise where an x87 FPU instruction, a WAIT/FWAIT instruction, or another SSE/SSE2/SSE3 instruction will catch a pending unmasked SIMD floating-point exception." This is also confirmed by the following testcase: --cut here-- #define _GNU_SOURCE #include #include #include #include static int counter; void __attribute__((noinline)) __divbyzero_ex (void) { float f = 1.0f, g = 0.0f; #ifdef __SSE_MATH__ asm volatile ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); #else asm volatile ("fdivp\t%1" : "+t" (f) : "u" (g) : "st(1)"); /* No need for fwait, exception is triggered by emitted fstp. */ #endif } void handler (int i) { exit (0); } int main () { struct sigaction s; sigemptyset (&s.sa_mask); s.sa_handler = handler; s.sa_flags = 0; sigaction (SIGFPE, &s, NULL); feenableexcept (FE_DIVBYZERO); __divbyzero_ex (); abort (); } --cut here-- libgcc/ChangeLog: 2020-04-19 Uroš Bizjak * config/i386/sfp-exceptions.c (__sfp_handle_exceptions) [__SSE_MATH__]: Remove unneeded assignments to volatile memory. libatomic/ChangeLog: 2020-04-19 Uroš Bizjak * config/x86/fenv.c (__atomic_feraiseexcept) [__SSE_MATH__]: Remove unneeded assignments to volatile memory. libgfortran/ChangeLog: 2020-04-19 Uroš Bizjak * config/fpu-387.h (local_feraiseexcept) [__SSE_MATH__]: Remove unneeded assignments to volatile memory. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline. Uros. diff --git a/libatomic/config/x86/fenv.c b/libatomic/config/x86/fenv.c index 7828162c68b..d7b1bbe5ea1 100644 --- a/libatomic/config/x86/fenv.c +++ b/libatomic/config/x86/fenv.c @@ -57,9 +57,7 @@ __atomic_feraiseexcept (int excepts) { float f = 0.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); asm volatile ("%vdivss\t{%0, %d0|%d0, %0}" : "+x" (f)); - r = f; /* Needed to trigger exception. */ #else asm volatile ("fdiv\t{%y0, %0|%0, %y0}" : "+t" (f)); /* No need for fwait, exception is triggered by emitted fstp. */ @@ -77,9 +75,7 @@ __atomic_feraiseexcept (int excepts) { float f = 1.0f, g = 0.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); asm volatile ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); - r = f; /* Needed to trigger exception. */ #else asm volatile ("fdivs\t%1" : "+t" (f) : "m" (g)); /* No need for fwait, exception is triggered by emitted fstp. */ @@ -105,9 +101,7 @@ __atomic_feraiseexcept (int excepts) { float f = 1.0f, g = 3.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); asm volatile ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); - r = f; /* Needed to trigger exception. */ #else asm volatile ("fdivs\t%1" : "+t" (f) : "m" (g)); /* No need for fwait, exception is triggered by emitted fstp. */ diff --git a/libgcc/config/i386/sfp-exceptions.c b/libgcc/config/i386/sfp-exceptions.c index c994491c650..31a24ced704 100644 --- a/libgcc/config/i386/sfp-exceptions.c +++ b/libgcc/config/i386/sfp-exceptions.c @@ -48,9 +48,7 @@ __sfp_handle_exceptions (int _fex) { float f = 0.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); asm volatile ("%vdivss\t{%0, %d0|%d0, %0}" : "+x" (f)); - r = f; /* Needed to trigger exception. */ #else asm volatile ("fdiv\t{%y0, %0|%0, %y0}" : "+t" (f)); /* No need for fwait, exception is triggered by emitted fstp. */ @@ -68,9 +66,7 @@ __sfp_handle_exceptions (int _fex) { float f = 1.0f, g = 0.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); asm volatile ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); - r = f; /* Needed to trigger exception. */ #else asm volatile ("fdivs\t%1" : "+t" (f) : "m" (g)); /* No need for fwait, exception is triggered by emitted fstp. */ @@ -96,9 +92,7 @@ __sfp_handle_exceptions (int _fex) { float f = 1.0f, g = 3.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); asm volatile ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); - r = f; /* Needed to trigger exception. */ #else asm volatile ("fdivs\t%1" : "+t" (f) : "m" (g)); /* No need for fwait, exception is triggered by emitted fstp. */ diff --git a/libgfortran/config/fpu-387.h b/libgfortran/config/fpu-387.h index 623e878b482..13be2045b72 100644 --- a/libgfortran/config/fpu-387.h +++ b/libgfortran/config/fpu-387.h @@ -103,9 +103,7 @@ local_feraiseexcept (int excepts) { float f = 0.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); __asm__ __volatile__ ("%vdivss\t{%0, %d0|%d0, %0}" : "+x" (f)); - r = f; /* Needed to trigger exception. */ #else __asm__ __volatile__ ("fdiv\t{%y0, %0|%0, %y0}" : "+t" (f)); /* No need for fwait, exception is triggered by emitted fstp. */ @@ -123,9 +121,7 @@ local_feraiseexcept (int excepts) { float f = 1.0f, g = 0.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); __asm__ __volatile__ ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); - r = f; /* Needed to trigger exception. */ #else __asm__ __volatile__ ("fdivs\t%1" : "+t" (f) : "m" (g)); /* No need for fwait, exception is triggered by emitted fstp. */ @@ -151,9 +147,7 @@ local_feraiseexcept (int excepts) { float f = 1.0f, g = 3.0f; #ifdef __SSE_MATH__ - volatile float r __attribute__ ((unused)); __asm__ __volatile__ ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g)); - r = f; /* Needed to trigger exception. */ #else __asm__ __volatile__ ("fdivs\t%1" : "+t" (f) : "m" (g)); /* No need for fwait, exception is triggered by emitted fstp. */