From patchwork Tue Sep 30 10:05:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 394862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E8AEB1400DD for ; Tue, 30 Sep 2014 20:05:24 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=ytr7svyO0pXmkQ/CdMbBGIEO5LkiuIsnDbyVKMGRi6c MZBUsj5iBF3Eif3UNyACuBSw+N9AvgXOGKMBkXAgosxVJEfcuzUyxg33eeoUtrfY VJQ155TdzMBv5kBmKuqzBwAjiQl2AO4513/iUxQt9YOgU9rPbQ/D71sRfr6YHN74 = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=UVITmaJfVEspA1EKyiynlCgq2G8=; b=bs9ywfOB9QOLKpA4C d2hQSo3Dg53m67x4jMiorx2pveFCSD6jsqWsYIn7+vthhFf8LDAxmSo5j8NbOhdi RPDdxRNql153BD3k6p58KtyBbWkz0ieQgA+jHZ/5XqddVcg+Y2YjKgV6ew9O1zjZ ouW1tAHIZI/s7gUdkTZNJPEnts= Received: (qmail 25741 invoked by alias); 30 Sep 2014 10:05:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25726 invoked by uid 89); 30 Sep 2014 10:05:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-lb0-f176.google.com Received: from mail-lb0-f176.google.com (HELO mail-lb0-f176.google.com) (209.85.217.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 30 Sep 2014 10:05:13 +0000 Received: by mail-lb0-f176.google.com with SMTP id p9so4023770lbv.21 for ; Tue, 30 Sep 2014 03:05:09 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.253.165 with SMTP id ab5mr43610085lbd.1.1412071509130; Tue, 30 Sep 2014 03:05:09 -0700 (PDT) Received: by 10.152.1.193 with HTTP; Tue, 30 Sep 2014 03:05:08 -0700 (PDT) Date: Tue, 30 Sep 2014 12:05:08 +0200 Message-ID: Subject: [PATCH, i386]: Enable reminder{sd, df, xf} and fmod{sf, df, xf} only for flag_finite_math_only. From: Uros Bizjak To: "gcc-patches@gcc.gnu.org" Cc: FX Coudert Hello! According to C99, reminder function returns: If x or y is a NaN, a NaN is returned. If x is an infinity, and y is not a NaN, a domain error occurs, and a NaN is returned. If y is zero, and x is not a NaN, a domain error occurs, and a NaN is returned. and fmod returns: If x or y is a NaN, a NaN is returned. If x is an infinity, a domain error occurs, and a NaN is returned. If y is zero, a domain error occurs, and a NaN is returned. If x is +0 (-0), and y is not zero, +0 (-0) is returned. However, x87 fprem and fprem1 instructions that are used to implement these builtin functions do not return NaN for infinities, but generate invalid-arithmetic-operand exception. Attached patch enables these builtins for finite math only, consistent with gcc documentation: '-ffinite-math-only': Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs. This option is not turned on by any '-O' option since it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/specifications for math functions. It may, however, yield faster code for programs that do not require the guarantees of these specifications. 2014-09-30 Uros Bizjak * config/i386/i386.md (fmodxf3): Enable for flag_finite_math_only only. (fmod3): Ditto. (fpremxf4_i387): Ditto. (reminderxf3): Ditto. (reminder3): Ditto. (fprem1xf4_i387): Ditto. Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. The patch also fixes ieee_2.f90 testsuite failure with FX's pending IEEE support improvement patch. 2014-09-30 Uros Bizjak * config/i386/i386.md (fmodxf3): Enable for flag_finite_math_only only. (fmod3): Ditto. (fpremxf4_i387): Ditto. (reminderxf3): Ditto. (reminder3): Ditto. (fprem1xf4_i387): Ditto. The patch will be committed to mainline and other release branches. Uros. Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 215705) +++ config/i386/i386.md (working copy) @@ -13813,7 +13813,8 @@ (set (reg:CCFP FPSR_REG) (unspec:CCFP [(match_dup 2) (match_dup 3)] UNSPEC_C2_FLAG))] - "TARGET_USE_FANCY_MATH_387" + "TARGET_USE_FANCY_MATH_387 + && flag_finite_math_only" "fprem" [(set_attr "type" "fpspc") (set_attr "mode" "XF")]) @@ -13822,7 +13823,8 @@ [(use (match_operand:XF 0 "register_operand")) (use (match_operand:XF 1 "general_operand")) (use (match_operand:XF 2 "general_operand"))] - "TARGET_USE_FANCY_MATH_387" + "TARGET_USE_FANCY_MATH_387 + && flag_finite_math_only" { rtx_code_label *label = gen_label_rtx (); @@ -13845,7 +13847,8 @@ [(use (match_operand:MODEF 0 "register_operand")) (use (match_operand:MODEF 1 "general_operand")) (use (match_operand:MODEF 2 "general_operand"))] - "TARGET_USE_FANCY_MATH_387" + "TARGET_USE_FANCY_MATH_387 + && flag_finite_math_only" { rtx (*gen_truncxf) (rtx, rtx); @@ -13884,7 +13887,8 @@ (set (reg:CCFP FPSR_REG) (unspec:CCFP [(match_dup 2) (match_dup 3)] UNSPEC_C2_FLAG))] - "TARGET_USE_FANCY_MATH_387" + "TARGET_USE_FANCY_MATH_387 + && flag_finite_math_only" "fprem1" [(set_attr "type" "fpspc") (set_attr "mode" "XF")]) @@ -13893,7 +13897,8 @@ [(use (match_operand:XF 0 "register_operand")) (use (match_operand:XF 1 "general_operand")) (use (match_operand:XF 2 "general_operand"))] - "TARGET_USE_FANCY_MATH_387" + "TARGET_USE_FANCY_MATH_387 + && flag_finite_math_only" { rtx_code_label *label = gen_label_rtx (); @@ -13916,7 +13921,8 @@ [(use (match_operand:MODEF 0 "register_operand")) (use (match_operand:MODEF 1 "general_operand")) (use (match_operand:MODEF 2 "general_operand"))] - "TARGET_USE_FANCY_MATH_387" + "TARGET_USE_FANCY_MATH_387 + && flag_finite_math_only" { rtx (*gen_truncxf) (rtx, rtx);