From patchwork Thu Apr 22 14:35:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1469237 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; 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=Pr0biPor; 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 4FR0N65rPHz9sVq for ; Fri, 23 Apr 2021 00:36:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00C0139AF812; Thu, 22 Apr 2021 14:36:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00C0139AF812 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619102163; bh=JJ7AVokv2QGTdTLIFvkUNzKBYD+F5/pItJi/MhvV6uM=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Pr0biPorL1zlPxuyVvT2jrRIZ6fazdsKK9MLGl3/3TX0oAVrlIh3T+MW+B6bOhZQu XhroFwMZbXIJLa2UHTjFWsvqgVA3I8GkQg0f9Aw9kwGXKA/vV3mrF2OoNzWXH+6+Zz 2LLnDM6DaBX10FnI83eZ/TvamwqNhypKcVccU/PA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id 859E6398B8AC for ; Thu, 22 Apr 2021 14:36:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 859E6398B8AC Received: by mail-qk1-x72f.google.com with SMTP id q136so25500926qka.7 for ; Thu, 22 Apr 2021 07:36:01 -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=JJ7AVokv2QGTdTLIFvkUNzKBYD+F5/pItJi/MhvV6uM=; b=CrpDEw8Ci1C7dREp1CojbThnLoKyRw4kfVyMxxYuCKbihKPQQLOa8yilcXEPv8l6aS 7hdAStEJqXRmsLkELh9vFwZ1fmhn473HskXKRMfKsrFpekSFyDJv2nY3RhG0VbSULdY4 izFxBwYS1g3Jg9ZeT1mCYqC6nTUan/Wb9ZK3ZZHwSkxG4P367be/Vct+OeJP7THSdn74 S6qLg275UfCisfvvTCA42V80mgMOocL0+ptvavPe9aAzJd6Vc4XRAnDo56r/E4bmeET/ NBpErmEMO30D1M4aQ8LG5wSlhOWSm+RiC44L4rKHGbxfI50Hf5WWMIHEKlUOVqkPtksE nhLg== X-Gm-Message-State: AOAM5309Yc+lIP7UMKzR+3dqWPjvgndtWZave7ldiHUBw00xQsCsM8+7 5G5i4Xk/tfjeMGLXwGZUZUWdc/6k+mDgbplfjj83kHz+dMn+pQ== X-Google-Smtp-Source: ABdhPJx8/IGTjEqlmynq5/ehyG9J/N1orJ4+zPTHO4rS7mMtON6AjeJtNChyENalZSP4yeqWGAivtD0dyIaTmJT6AjA= X-Received: by 2002:a37:bb42:: with SMTP id l63mr3988679qkf.127.1619102160903; Thu, 22 Apr 2021 07:36:00 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 22 Apr 2021 16:35:49 +0200 Message-ID: Subject: i386: Fix unsigned int -> double conversion on i386 w/ -mfpmath=sse [PR100119] To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-9.2 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" 2021-04-22 Uroš Bizjak gcc/ PR target/100119 * config/i386/i386-expand.c (ix86_expand_convert_uns_sidf_sse): Remove the sign with FE_DOWNWARD, where x - x = -0.0. gcc/testsuite/ PR target/100119 * gcc.target/i386/pr100119.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Pushed to master. Uros. diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 166c23ddb4d..516440eb5c1 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -1550,6 +1550,8 @@ ix86_expand_convert_uns_sixf_sse (rtx, rtx) gcc_unreachable (); } +static rtx ix86_expand_sse_fabs (rtx op0, rtx *smask); + /* Convert an unsigned SImode value into a DFmode. Only currently used for SSE, but applicable anywhere. */ @@ -1569,6 +1571,11 @@ ix86_expand_convert_uns_sidf_sse (rtx target, rtx input) x = const_double_from_real_value (TWO31r, DFmode); x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT); + + /* Remove the sign with FE_DOWNWARD, where x - x = -0.0. */ + if (HONOR_SIGNED_ZEROS (DFmode) && flag_rounding_math) + x = ix86_expand_sse_fabs (x, NULL); + if (x != target) emit_move_insn (target, x); } diff --git a/gcc/testsuite/gcc.target/i386/pr100119.c b/gcc/testsuite/gcc.target/i386/pr100119.c new file mode 100644 index 00000000000..be9472eb939 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr100119.c @@ -0,0 +1,28 @@ +/* PR target/100119 */ +/* { dg-do run { target sse2_runtime } } */ +/* { dg-require-effective-target fenv } */ +/* { dg-options "-O2 -frounding-math -msse2 -mno-avx512f -mfpmath=sse" } */ + +#include + +double +__attribute__((noinline)) +test (unsigned int x) +{ + return x; +} + +int +main () +{ + double result; + + fesetround (FE_DOWNWARD); + + result = test (0); + + if (__builtin_signbit (result) != 0) + __builtin_abort (); + + return 0; +}