From patchwork Fri Oct 20 09:53:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 828529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464613-incoming=patchwork.ozlabs.org@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.b="hpxYq073"; dkim-atps=neutral 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 3yJLhw617cz9t5q for ; Fri, 20 Oct 2017 20:53:35 +1100 (AEDT) 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:from:date:message-id:subject:to:cc:content-type; q=dns; s=default; b=IMV8Y/lR/iIFGXuBZVgzocWMCGJlzw+EXLmmaR3rIJr lKOHiQuqMSbv0tqEBNPbpzufFpIkIkoHDud2F5OVeEfgaKL6Ua871TWpK5mukVqQ jxAB6X9SR/Mv6PP23YJ0lmxG73BPFSbgN5E2GAotCgDDdWLINe28AVjLZ9SzgbwQ = 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:from:date:message-id:subject:to:cc:content-type; s=default; bh=zrJ/4JD2B6jDP2JoLoPcgxiNaJQ=; b=hpxYq073Z0pQ+Kxx2 nHbi7cdwOyBglS87eySv3CgX93QyvgLZ02mPa+GkfsgpZxH917THr5MkkdMXCD0m yG0UrI6LqonnBKV8B0q4QQxDfk9T2rYrBjI1xMilRPDrJaZvs2pKGkLTw1h6EdR8 aqtC2zTrBhUYoosUDGbUhmY7ek= Received: (qmail 56129 invoked by alias); 20 Oct 2017 09:53:27 -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 56113 invoked by uid 89); 20 Oct 2017 09:53:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2221, hello! X-HELO: mail-it0-f44.google.com Received: from mail-it0-f44.google.com (HELO mail-it0-f44.google.com) (209.85.214.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Oct 2017 09:53:25 +0000 Received: by mail-it0-f44.google.com with SMTP id c3so13377269itc.3 for ; Fri, 20 Oct 2017 02:53:25 -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:cc; bh=8kMBy+rT1DZHR1wKWPpy0rqHtmoI3DNM3+kJ0P/33eM=; b=URz08gEVUCiBhluFeMpXjZACecPr8cMErPe2s+Fzy3n9Vd3i3SwEi3zS7rP0gCZQ9E +HjxGH9U6k2k1/fhOHksjyG0sCbNd32etGHYP9sdeO9QrUHDS2KQ5A07/2mt3X3+InRN QdpNMLYnSiVvUaYVlVMsdvItTAKLGCw0vFHqZrjDL1nYskZRSoJZ/TXO596hHA6mTzA4 rEpNeX+uyG+6otaS02Rk+4jujnRRUQ6QHk4nGKu+mA8TbTF6yNfitl5/6DB36isRyKVU QJEf/E2TJV6/wH/nvjRDqFTo/2WmK7xwFYEsvTtDrwbcTC2TZ2+abLjm2V4wr/UMuf2u TzuQ== X-Gm-Message-State: AMCzsaVmxT41maidRaEGdzd3Z1V/Ehfr4baQ3E5d3KFy4Yme2I89V28L +k9tnF4q6XAfW2siH4wsNLjEYv7qviAFSnmcbsxX5Q== X-Google-Smtp-Source: ABhQp+R9efyTwMzadN014N++YzHnyaOWJojMRDKqWlwCmgJ9NQ4damp8mxAFtGQaCjonzCgDxNomU+eZKfdwYW5ZZ58= X-Received: by 10.36.161.15 with SMTP id y15mr44295ite.151.1508493203749; Fri, 20 Oct 2017 02:53:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.74.18 with HTTP; Fri, 20 Oct 2017 02:53:23 -0700 (PDT) From: Uros Bizjak Date: Fri, 20 Oct 2017 11:53:23 +0200 Message-ID: Subject: [RFC PATCH, i386]: Make FP inequality comparisons trapping on qNaN. To: "gcc-patches@gcc.gnu.org" Cc: "Joseph S. Myers" Hello! Attached patch makes FP inequality comparisons trap on qNaN. There is an old comment mentioned reversible comparisons, but middle end doesn't reverse them anymore (a couple of weeks ago, reversed comparisons were removed from i386.md): /* ??? In order to make all comparisons reversible, we do all comparisons non-trapping when compiling for IEEE. Once gcc is able to distinguish all forms trapping and nontrapping comparisons, we can make inequality comparisons trapping again, since it results in better code when using FCOM based compares. */ FCOM compares allow FP and integer memory operands. This is also what ICC produces with -fp-model strict, so I see no reason for GCC to produce different and inferior code. 2017-10-20 Uros Bizjak * config/i386/i386.c (ix86_fp_compare_mode): Return CCFPmode for ordered inequality comparisons even with TARGET_IEEE_FP. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. If there are no comments, I plan to commit the patch to mainline early next week. Uros. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 45a219741dbb..7ff222be9aaf 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -21500,14 +21500,35 @@ ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1) Return the appropriate mode to use. */ machine_mode -ix86_fp_compare_mode (enum rtx_code) -{ - /* ??? In order to make all comparisons reversible, we do all comparisons - non-trapping when compiling for IEEE. Once gcc is able to distinguish - all forms trapping and nontrapping comparisons, we can make inequality - comparisons trapping again, since it results in better code when using - FCOM based compares. */ - return TARGET_IEEE_FP ? CCFPUmode : CCFPmode; +ix86_fp_compare_mode (enum rtx_code code) +{ + if (!TARGET_IEEE_FP) + return CCFPmode; + + switch (code) + { + case GT: + case GE: + case LT: + case LE: + return CCFPmode; + + case EQ: + case NE: + + case LTGT: + case UNORDERED: + case ORDERED: + case UNLT: + case UNLE: + case UNGT: + case UNGE: + case UNEQ: + return CCFPUmode; + + default: + gcc_unreachable (); + } } machine_mode