From patchwork Sat May 6 14:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 90758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1070453vqo; Sat, 6 May 2023 07:01:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HE1Y8wcOO38y64DZo4/sT9CueBqcdMVnW72iau6ze6y5ERA0UlcCOgXvqufo7ZndF3mFR X-Received: by 2002:a17:907:97cf:b0:957:28ed:aea5 with SMTP id js15-20020a17090797cf00b0095728edaea5mr4294511ejc.10.1683381662853; Sat, 06 May 2023 07:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683381662; cv=none; d=google.com; s=arc-20160816; b=Xzy58XwnYAhVPwN4rwmY7LEDMhRaCj6XEV1iP7jCUQvHMQaKKMKZiPRBxCC9wZFEos BuX/gigeX5qDW/E/XxPKjKI8oO8QNG8XhBVUIVwOfURvOWBIheggMyQ0rLZPyzpaFkbz O7JQijUCwLkvRQyrzNqXEwyxf68Unh8eDAXYsI+lwu5m/dE6Jk3nYWGKcPZxDVaXDlwg oitjILTBJRochFNElHXV/gQ2V/XKLW3lfudAUGYwpHZ/hJRgRqZCv2EHpmPeAx86Nqz/ 7VPyaod7W2ZubQuUsRhxntbgNBx2mZSg57TRQ9BBPEXG8C4x+CtgpqXOErXfhJUP16+q wViw== 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:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=aS2CDXOxX6TZPXsGyp2vJlUMD76cBcSAUU3E8sSswcI=; b=GlNRnVdvg5rf5RGvzozKCigX+s6HyrjRUXIHlvyvhm2XBuArDs6iVwafnJmYXl566P qRbAQj/ifBJ0bIYWnax6kr0SXsJ3QaKQb+kCDpU6ev/3XqaHNUGxWZGsXHv+i1DcGe2N tCz+M2WaejBImN85RyWTjEwA8L9yfQ7s7nXlZOIAucbXApV0L/ORPFTwgKfKvM6DJmKL Yxe0/jBGkHTGV6dR9QXmN5CfEUzQqm6iJqnKckXXNPkZ6hoH/MX/Odc02AdS17Y5UX7O NQVG04vePOO9AKVpKp5mGPpcpEDxkVCR4CJqvZkE9UahlGEWVx9crqH0nlsG0Tr2AdBR khqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=CYGpw2l7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id mj8-20020a170906af8800b00932835201fesi3032758ejb.635.2023.05.06.07.01.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 07:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=CYGpw2l7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 C94D03856090 for ; Sat, 6 May 2023 14:00:53 +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 019953858D1E for ; Sat, 6 May 2023 14:00:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 019953858D1E 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=aS2CDXOxX6TZPXsGyp2vJlUMD76cBcSAUU3E8sSswcI=; b=CYGpw2l7xbIn/21mLP/1TrcoF4 +L0cE4Q2lBPhWyUTCBP7qMKh28BYv2c66751X4vqKKzmZRWHE2wL8jmbfg1n0H5MydS6coHZj6Tsk fB1z5nVy91qV9oBScMCz/XMoPowP7N4ic1QUpPfKPVqUkIbGaEkLutCtCQU6ELflwJNl5uDTHBnP3 8g62XCEyhKKytSZ3qKFxf/G3bqcakUGStj8OMtqzO8lQIUSQ0+54g0GCSYF0m+8VirRDWTOw3zlOO KSrb9sDbwi+NUZBBvn52HlglZIzJSClQicHrxf0/AQQnTjne7RA8tKqdIBfseQJ1+7RtUZpS3jEO6 fTfghNzg==; Received: from host86-169-41-81.range86-169.btcentralplus.com ([86.169.41.81]:49881 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pvISY-0007o6-1Z; Sat, 06 May 2023 10:00:26 -0400 From: "Roger Sayle" To: "'GCC Patches'" Cc: "'Uros Bizjak'" Subject: [x86_64 PATCH] Introduce insvti_highpart define_insn_and_split. Date: Sat, 6 May 2023 15:00:24 +0100 Message-ID: <003101d98023$1be6c6e0$53b454a0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmAIf14lZHcSOl4SrG6KoO4k2XMMg== 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=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, 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?1765153610737741082?= X-GMAIL-MSGID: =?utf-8?q?1765153610737741082?= Hi Uros, This is a repost/respin of a patch that was conditionally approved: https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609470.html This patch adds a convenient post-reload splitter for setting/updating the highpart of a TImode variable, using i386's previously added split_double_concat infrastructure. For the new test case below: __int128 foo(__int128 x, unsigned long long y) { __int128 t = (__int128)y << 64; __int128 r = (x & ~0ull) | t; return r; } mainline GCC with -O2 currently generates: foo: movq %rdi, %rcx xorl %eax, %eax xorl %edi, %edi orq %rcx, %rax orq %rdi, %rdx ret with this patch, GCC instead now generates the much better: foo: movq %rdi, %rcx movq %rcx, %rax ret It turns out that the -m32 equivalent of this testcase, already avoids using explict orl/xor instructions, as it gets optimized (in combine) by a completely different path. Given that this idiom isn't seen in 32-bit code (so this pattern doesn't match with -m32), and also that the shorter 32-bit AND bitmask is represented as a CONST_INT rather than a CONST_WIDE_INT, this new define_insn_and_split is implemented for just TARGET_64BIT rather than contort a "generic" implementation using DWI mode iterators. 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. Ok for mainline now that we're back in stage 1? 2023-05-06 Roger Sayle gcc/ChangeLog * config/i386/i386.md (any_or_plus): Move definition earlier. (*insvti_highpart_1): New define_insn_and_split to overwrite (insv) the highpart of a TImode register/memory. gcc/testsuite/ChangeLog * gcc.target/i386/insvti_highpart-1.c: New test case. Thanks again, Roger diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index d49f1cd..62cafe7 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -3479,6 +3479,31 @@ "mov{b}\t{%h1, %h0|%h0, %h1}" [(set_attr "type" "imov") (set_attr "mode" "QI")]) + +(define_code_iterator any_or_plus [plus ior xor]) +(define_insn_and_split "*insvti_highpart_1" + [(set (match_operand:TI 0 "nonimmediate_operand" "=ro,r,r,&r") + (any_or_plus:TI + (and:TI + (match_operand:TI 1 "nonimmediate_operand" "r,m,r,m") + (match_operand:TI 3 "const_scalar_int_operand" "n,n,n,n")) + (ashift:TI + (zero_extend:TI + (match_operand:DI 2 "nonimmediate_operand" "r,r,m,m")) + (const_int 64))))] + "TARGET_64BIT + && CONST_WIDE_INT_P (operands[3]) + && CONST_WIDE_INT_NUNITS (operands[3]) == 2 + && CONST_WIDE_INT_ELT (operands[3], 0) == -1 + && CONST_WIDE_INT_ELT (operands[3], 1) == 0" + "#" + "&& reload_completed" + [(clobber (const_int 0))] +{ + operands[4] = gen_lowpart (DImode, operands[1]); + split_double_concat (TImode, operands[0], operands[4], operands[2]); + DONE; +}) ;; Floating point push instructions. @@ -11573,7 +11598,6 @@ (set_attr "mode" "QI")]) ;; Split DST = (HI<<32)|LO early to minimize register usage. -(define_code_iterator any_or_plus [plus ior xor]) (define_insn_and_split "*concat3_1" [(set (match_operand: 0 "nonimmediate_operand" "=ro,r") (any_or_plus: diff --git a/gcc/testsuite/gcc.target/i386/insvti_highpart-1.c b/gcc/testsuite/gcc.target/i386/insvti_highpart-1.c new file mode 100644 index 0000000..4ae9ccf --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/insvti_highpart-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2" } */ + +__int128 foo(__int128 x, unsigned long long y) +{ + __int128 t = (__int128)y << 64; + __int128 r = (x & ~0ull) | t; + return r; +} + +/* { dg-final { scan-assembler-not "xorl" } } */ +/* { dg-final { scan-assembler-not "orq" } } */