From patchwork Fri Aug 5 13:14:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:20da:b0:2d3:3019:e567 with SMTP id n26csp188997pxc; Fri, 5 Aug 2022 06:14:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WqH1xK4PzpMvomQ5yT2BdXZcVw4V00yronEjyfoFSpwxMsnGZr/O+vv2+Vsn3VnPjm8td X-Received: by 2002:a17:907:2894:b0:730:df55:b65f with SMTP id em20-20020a170907289400b00730df55b65fmr3929220ejc.138.1659705298464; Fri, 05 Aug 2022 06:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659705298; cv=none; d=google.com; s=arc-20160816; b=uuI3dSPGCOfM6mJx6ld7PKFAz5Di2UwossjVvwS120inZ/diZBssYVhXa22cDop7Px db6cUhQA0qWQjMSijc4AanCrooRHlIa8i8lndF3/CXVM3rk88GzS7drm7DJjnQdZ0XDg KfDmGoE4uUxFAAfLx4bBJQ8Jf83Bb30K79gliTP9SRnP8gOjCv3P15nELNREd4XOkKk7 U4fNnzcvi9jXt2FmQ/uzVOc3+0lLA+D6qrU1PTiYnlat0h0qA5yO1Hc/HsZ5iAB/WPRM C5gCSDaSvoMk2SRHjrP0MYvfWtIPo7q8TjTueaIcbPIC5r8ViRWfAxE0LjgniBwepCZM EX9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=cMbZCDvO5hkULCXJdxA+DQiHAFXRq9QQAkvD9rtD7G8=; b=BzN45abKTlmv1D2TxpgiKeE1h+y9rOB+UqFKiqXnGFXRYxRanQV2UiFLdHZQXzuIcu lSwqPxhX8ACdcPoKtKUsjCLn7wjh+XTmQ+9zbmd0iR0UQCJPGHPUNN+49m82ltrQ8SVD bhAwEpgauEMJBquJC6R8CAgFMjRmvusIWxXUfpOf7qnCq00yvT17afGI1tq3QJ+Hgj9e x/oskkSzFz/dOC5Vf1Im3qdexVtkpNLnqoJcJ7OGh6FJmuz2yc/CPhtJYYhhc/5WRDMk liTtQ/W6naaCY9Q6wgczolcNv3tKa7iS9clEMpuj8GaO+QrSEgiMM6Wt1lPMDZmBLL3R +0pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=PqOT4WLs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x4-20020a1709060a4400b0072b3a874867si2832766ejf.874.2022.08.05.06.14.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 06:14:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=PqOT4WLs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E80738582A3 for ; Fri, 5 Aug 2022 13:14:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 901393858C53 for ; Fri, 5 Aug 2022 13:14:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 901393858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cMbZCDvO5hkULCXJdxA+DQiHAFXRq9QQAkvD9rtD7G8=; b=PqOT4WLsnxNRMtvD1RLCyII4lQ 8/46goC0a/2E54VhqCAXbK/O8gcNhAp3pILdf7Vh3XqqJZm9YY5QDY5Ikd6xVUeupCNre4of1861r QJ7SDMUdWCYJYDnmTyUcTcHdeXPxfOgx3nmNWRqkTUN1Fy6BteSu0us80ZlulYHkUA5tX9jFKLiXx Q4sAfB0p1afAWyVYX7eVUISUGXZBxo4QkT1ra5AKKCdIB53gRnDwZYXZAp42+GDEYogBB7vleYjMS AMNd407nR/ZXUORrihlLTuAC4tCBrPqzYGk3JBqBIrHHKnrJQGLZEI8Hf09dg5DlfMT0i5Q56/Cii WmK0uQHA==; Received: from [185.62.158.67] (port=65344 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oJx9b-0003cJ-M5; Fri, 05 Aug 2022 09:14:15 -0400 From: "Roger Sayle" To: Subject: [x86_64 PATCH] Allow any immediate constant in *cmp_doubleword splitter. Date: Fri, 5 Aug 2022 14:14:14 +0100 Message-ID: <014501d8a8cd$43413aa0$c9c3afe0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdiozIqwtNppLEjKT1mZV42r5nSnmQ== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LOTS_OF_MONEY, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740327143531000905?= X-GMAIL-MSGID: =?utf-8?q?1740327143531000905?= This patch tweaks i386.md's *cmp_doubleword splitter's predicate to allow general_operand, not just x86_64_hilo_general_operand, to improve code generation. As a general rule, i386.md's _doubleword splitters should be post-reload splitters that require integer immediate operands to be x86_64_hilo_int_operand, so that each part is a valid word mode immediate constant. As an exception to this rule, doubleword patterns that must be split before reload, because they require additional scratch registers, can take advantage of this ability to create new pseudos, to accept any immediate constant, and call force_reg on the high and/or low parts if they are not suitable immediate operands in word mode. The benefit is shown in the new cmpti3.c test case below. __int128 x; int foo() { __int128 t = 0x1234567890abcdefLL; return x == t; } where GCC with -O2 currently generates: movabsq $1311768467294899695, %rax xorl %edx, %edx xorq x(%rip), %rax xorq x+8(%rip), %rdx orq %rdx, %rax sete %al movzbl %al, %eax ret but with this patch now generates: movabsq $1311768467294899695, %rax xorq x(%rip), %rax orq x+8(%rip), %rax sete %al movzbl %al, %eax ret This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32}, with no new failures. The first two new test cases aren't affected by this patch, but as I had them in my directory, it seemed reasonable to increase the testsuite's coverage of TImode comparison code generation. Ok for mainline? 2022-08-05 Roger Sayle gcc/ChangeLog * config/i386/i386.md (*cmp_doubleword): Change predicate for x86_64_hilo_general_operand to general operand. Call force_reg on parts that are not x86_64_immediate_operand. gcc/testsuite/ChangeLog * gcc.target/i386/cmpti1.c: New test case. * gcc.target/i386/cmpti2.c: Likewise. * gcc.target/i386/cmpti3.c: Likewise. Thanks in advance, Roger diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 298e4b3..fd30c57 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -1510,7 +1510,7 @@ (define_insn_and_split "*cmp_doubleword" [(set (reg:CCZ FLAGS_REG) (compare:CCZ (match_operand: 0 "nonimmediate_operand") - (match_operand: 1 "x86_64_hilo_general_operand")))] + (match_operand: 1 "general_operand")))] "ix86_pre_reload_split ()" "#" "&& 1" @@ -1544,7 +1544,12 @@ else if (operands[0] == constm1_rtx) emit_insn (gen_one_cmpl2 (operands[4], operands[1])); else - emit_insn (gen_xor3 (operands[4], operands[0], operands[1])); + { + if (CONST_SCALAR_INT_P (operands[1]) + && !x86_64_immediate_operand (operands[1], mode)) + operands[1] = force_reg (mode, operands[1]); + emit_insn (gen_xor3 (operands[4], operands[0], operands[1])); + } if (operands[3] == const0_rtx) operands[5] = operands[2]; @@ -1558,7 +1563,12 @@ else if (operands[2] == constm1_rtx) emit_insn (gen_one_cmpl2 (operands[5], operands[3])); else - emit_insn (gen_xor3 (operands[5], operands[2], operands[3])); + { + if (CONST_SCALAR_INT_P (operands[3]) + && !x86_64_immediate_operand (operands[3], mode)) + operands[3] = force_reg (mode, operands[3]); + emit_insn (gen_xor3 (operands[5], operands[2], operands[3])); + } } }) diff --git a/gcc/testsuite/gcc.target/i386/cmpti1.c b/gcc/testsuite/gcc.target/i386/cmpti1.c new file mode 100644 index 0000000..1c5f121 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/cmpti1.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ +int eq(__int128 x, __int128 y) { return x == y; } +int ne(__int128 x, __int128 y) { return x != y; } +/* { dg-final { scan-assembler-times "xorq" 4 } } */ +/* { dg-final { scan-assembler-times "setne" 1 } } */ +/* { dg-final { scan-assembler-times "sete" 1 } } */ + diff --git a/gcc/testsuite/gcc.target/i386/cmpti2.c b/gcc/testsuite/gcc.target/i386/cmpti2.c new file mode 100644 index 0000000..ad95729 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/cmpti2.c @@ -0,0 +1,12 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ + +__int128 x; +__int128 y; + +int eq() { return x == y; } +int ne() { return x != y; } + +/* { dg-final { scan-assembler-times "xorq" 4 } } */ +/* { dg-final { scan-assembler-times "setne" 1 } } */ +/* { dg-final { scan-assembler-times "sete" 1 } } */ diff --git a/gcc/testsuite/gcc.target/i386/cmpti3.c b/gcc/testsuite/gcc.target/i386/cmpti3.c new file mode 100644 index 0000000..302efd2 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/cmpti3.c @@ -0,0 +1,13 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ + +__int128 x; +int foo() +{ + __int128 t = 0x1234567890abcdefLL; + return x == t; +} + +/* { dg-final { scan-assembler-times "movabsq" 1 } } */ +/* { dg-final { scan-assembler-times "xorq" 1 } } */ +/* { dg-final { scan-assembler-not "xorl" } } */