From patchwork Wed Oct 11 21:22:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 824581 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-463985-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="sQp/wAyp"; 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 3yC6Qj5ZTvz9t2W for ; Thu, 12 Oct 2017 08:23:06 +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:content-type; q= dns; s=default; b=BhoCPABSeCYEQ1L8sT14nXd8sByBMmrTPhwZbpXLtRtidV udrlFhzyK+BCcmswt6wW4rQ7LvJ3hNQ3ci3ja2R9e5GAzj32KPveC40KtVf13Kac j1zJXTckdhcSsdsBR4QfvTyePomQx7nDURNupRt1BTHAJVIaXzQqSVsqJbHvY= 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:content-type; s= default; bh=pDVunXtN7d1jRXegfOkq4d+kZ94=; b=sQp/wAypdr2MPJMhRfbW BxcKv3EnqUGIuqqVQedmSSZmQ3sKmkCzIeweUf7OQYtBWw3VvT8Ll0KSvYONQpFm Bko0U/vxPAB5a+EPZD8aDXwRjXC548OMZnL+xv0cgi9Vka7IMT4zPc3Q7Bf+Ca0V rclMl0is1gfsDrz1WHaZnfM= Received: (qmail 119049 invoked by alias); 11 Oct 2017 21:22:57 -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 118180 invoked by uid 89); 11 Oct 2017 21:22:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f177.google.com Received: from mail-io0-f177.google.com (HELO mail-io0-f177.google.com) (209.85.223.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Oct 2017 21:22:56 +0000 Received: by mail-io0-f177.google.com with SMTP id n137so3318356iod.6 for ; Wed, 11 Oct 2017 14:22:55 -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=gckz4oF2sS1z4IOWyEY5UTNUgh5CSvEuN4d18+5IvRs=; b=dCA+7lXSSIt2D6DccW5Ifcm39Sa5Ic0TkPJdQVWpgQbyC6QMic01Op2dLIDPL32q8f a4oFEtqEpkWoB7j2yST+kTBMX0zJ57iO+LLp+z8Yq7SCjneHVl+Wjv1ZAKEZFJIWxWpv MCdaWl8FynajjKw3qsPszY5qDGgmUEuZFtsyLL1cJVPxohTfEGINOcvB2GiG5H475fx2 +Sr3YbSuEl72BEBnchrsSPgbrsJYxOyJhS6nnr/upcURMvQHK4rjOKdVWmAoBlcbAq28 +0MMBzX2/P45BSXdSWI9jUurPmauNtJPuYcgrNWCnxMVbAFZArROuQ2yfrOqjFug2VF5 SjYg== X-Gm-Message-State: AMCzsaVYjPKov4Ot6sAnVZ2mgUtOpuQsSHrnChEVsJcztDMH02CWdiFU L/uoMR0BqaXNEnyKZTeAxE8MqKpc+Xdbuwh4QiLIsw== X-Google-Smtp-Source: AOwi7QA9QZhW/qB4zOyrzSGNrr/2FL2DIec7YiRjCHNURDYPZZf0exl1ZNcaOrpqYUk+766hKgngm3N+tTRWgWibeYw= X-Received: by 10.107.171.199 with SMTP id u190mr505442ioe.129.1507756974070; Wed, 11 Oct 2017 14:22:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.76.19 with HTTP; Wed, 11 Oct 2017 14:22:53 -0700 (PDT) From: Uros Bizjak Date: Wed, 11 Oct 2017 23:22:53 +0200 Message-ID: Subject: [PATCH, i386]: Re-enable FICOM instruction with IX86_FPCMP_SAHF FP comparison strategy To: "gcc-patches@gcc.gnu.org" Hello! "*cmp__cc_i387" is never matched by combine. The order of operands in x87 ficom compare is forced by combine in simplify_comparison () function. Float operator is treated as RTX_OBJ with a precedence over other operators and is always put in the first place. Patch defines TARGET_CANONICALIZE_COMPARISON target hook to swap condition and operands to match ficom instruction. 2017-10-11 Uros Bizjak * config/i386/i386.c (ix86_canonicalize_comparison): New function. (TARGET_CANONICALIZE_COMPARISON): Define. testsuite/ChangeLog: 2017-10-11 Uros Bizjak * gcc.target/i386/387-ficom-2.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline SVN. Uros. Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 253653) +++ config/i386/i386.c (working copy) @@ -4792,6 +4792,30 @@ ix86_conditional_register_usage (void) fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = ""; } +/* Canonicalize a comparison from one we don't have to one we do have. */ + +static void +ix86_canonicalize_comparison (int *code, rtx *op0, rtx *op1, + bool op0_preserve_value) +{ + /* The order of operands in x87 ficom compare is forced by combine in + simplify_comparison () function. Float operator is treated as RTX_OBJ + with a precedence over other operators and is always put in the first + place. Swap condition and operands to match ficom instruction. */ + if (!op0_preserve_value + && GET_CODE (*op0) == FLOAT && MEM_P (XEXP (*op0, 0)) && REG_P (*op1)) + { + enum rtx_code scode = swap_condition ((enum rtx_code) *code); + + /* We are called only for compares that are split to SAHF instruction. + Ensure that we have setcc/jcc insn for the swapped condition. */ + if (ix86_fp_compare_code_to_integer (scode) != UNKNOWN) + { + std::swap (*op0, *op1); + *code = (int) scode; + } + } +} /* Save the current options */ @@ -49649,6 +49673,9 @@ ix86_run_selftests (void) #undef TARGET_CONDITIONAL_REGISTER_USAGE #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage +#undef TARGET_CANONICALIZE_COMPARISON +#define TARGET_CANONICALIZE_COMPARISON ix86_canonicalize_comparison + #undef TARGET_LOOP_UNROLL_ADJUST #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust Index: testsuite/gcc.target/i386/387-ficom-2.c =================================================================== --- testsuite/gcc.target/i386/387-ficom-2.c (nonexistent) +++ testsuite/gcc.target/i386/387-ficom-2.c (working copy) @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ia32 } */ +/* { dg-skip-if "" { *-*-* } { "-march=*" } { "-march=i386" } } */ +/* { dg-options "-Os -march=i386 -ffast-math -masm=att" } */ + +#include "387-ficom-1.c" + +/* { dg-final { scan-assembler-times "ficomps" 3 } } */ +/* { dg-final { scan-assembler-times "ficompl" 3 } } */