From patchwork Mon May 18 15:55:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1292624 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=8.43.85.97; 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=tHdMxqi9; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 49QkBS1F4Zz9sRW for ; Tue, 19 May 2020 01:55:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57E5C388F06B; Mon, 18 May 2020 15:55:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57E5C388F06B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589817340; bh=P5iu1h7BmOToigMHsA3SHXNdtraWBAX+s4iNFUbHusw=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tHdMxqi9wxAfD9waPk80XpSDzTNszvYYIA6DtzVokNDZj2AaPQrGGDMqurvT0ikco z9fY0knQLEQjxaclXPfbh9s2qXQQ8ipNxvpORI4p1oGrCltlMdbpyOoX6ZYyedPKBQ XrWu/ndEFK1CaY8hHUubBt/fJTVvAHn3MIKtxrOI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 13BA4388A835 for ; Mon, 18 May 2020 15:55:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 13BA4388A835 Received: by mail-il1-x132.google.com with SMTP id n11so10329305ilj.4 for ; Mon, 18 May 2020 08:55:38 -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=P5iu1h7BmOToigMHsA3SHXNdtraWBAX+s4iNFUbHusw=; b=T+7wQzWNdM+Y3Hs+p6x7N2rBzTPCn5gB0zAjU2bWEDQc89rfijotNa60BQDuYO9Jw+ oTh5IZEjQ+DPoIpLBbS33lxKpRc6uDG+qkcLnfNQN6Os9mqyAgU+gYKCSRXX17tY6U6K YGP4MPAGx/IaslUDC7ECTG5rHp0Zz1z8mR03ELBzQbMMgCLJrCSEQXgNCXiStqJZkQfK rg63UmqoUIzUp0UYmXS36f+sqNWRtkOpf3rva0zGlSN7XoMQYsroUzlYcpVA5sUcJSal tkOkhoN9TPgy7uC1LQnTfenEBqKB75FC2GBqx4XzAPFDaYntdPvegPzp0s79Wq5vJ3TS muJw== X-Gm-Message-State: AOAM5310XtnGokxRrCDKM1xrQrjnACvrFhzvWYlNfGIl0NG58DrdzxUq O7EzbVS7GxVeEQhyY/yZJKnx3iY5HRktswsm6bhSjfe80/A= X-Google-Smtp-Source: ABdhPJw/qEP2QkLx4OUddgp7JyJi38DhEkf7VNKX+qiVQW7hpY80Rcvfd3T0V/77Fm9yW3aOJc5LXxBsDGNxv1VBq74= X-Received: by 2002:a92:8c8a:: with SMTP id s10mr16406557ill.307.1589817337137; Mon, 18 May 2020 08:55:37 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 18 May 2020 17:55:25 +0200 Message-ID: Subject: [committed] i386: Avoid reversing a non-trapping comparison to a trapping one [PR95169] To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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" gcc/ChangeLog: 2020-05-18 Uroš Bizjak PR target/95169 * config/i386/i386-expand.c (ix86_expand_int_movcc): Avoid reversing a non-trapping comparison to a trapping one. testsuite/ChangeLog: 2020-05-18 Uroš Bizjak PR target/95169 * gcc.target/i386/pr95169.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros. diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 2865cced66c..79f827fd653 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -3057,11 +3057,14 @@ ix86_expand_int_movcc (rtx operands[]) { gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode)); - /* We may be reversing unordered compare to normal compare, that - is not valid in general (we may convert non-trapping condition - to trapping one), however on i386 we currently emit all - comparisons unordered. */ - new_code = reverse_condition_maybe_unordered (code); + /* We may be reversing a non-trapping + comparison to a trapping comparison. */ + if (HONOR_NANS (cmp_mode) && flag_trapping_math + && code != EQ && code != NE + && code != ORDERED && code != UNORDERED) + new_code = UNKNOWN; + else + new_code = reverse_condition_maybe_unordered (code); } else new_code = ix86_reverse_condition (code, cmp_mode); @@ -3213,11 +3216,15 @@ ix86_expand_int_movcc (rtx operands[]) { gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode)); - /* We may be reversing unordered compare to normal compare, - that is not valid in general (we may convert non-trapping - condition to trapping one), however on i386 we currently - emit all comparisons unordered. */ - new_code = reverse_condition_maybe_unordered (code); + /* We may be reversing a non-trapping + comparison to a trapping comparison. */ + if (HONOR_NANS (cmp_mode) && flag_trapping_math + && code != EQ && code != NE + && code != ORDERED && code != UNORDERED) + new_code = UNKNOWN; + else + new_code = reverse_condition_maybe_unordered (code); + } else { diff --git a/gcc/testsuite/gcc.target/i386/pr95169.c b/gcc/testsuite/gcc.target/i386/pr95169.c new file mode 100644 index 00000000000..91411744228 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr95169.c @@ -0,0 +1,28 @@ +/* PR target/95169 */ +/* { dg-do run { target ia32 } } */ +/* { dg-options "-O0 -march=i386 -mtune=generic" } */ +/* { dg-require-effective-target fenv_exceptions } */ + +#include + +void +f (double y) +{ + if (__builtin_expect (y == 0.0, 0)) + __builtin_abort (); +} + +int +main (void) +{ + double y = __builtin_nan (""); + + feclearexcept (FE_INVALID); + + f (y); + + if (fetestexcept (FE_INVALID)) + __builtin_abort (); + + return 0; +}