From patchwork Fri Jan 5 07:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiahao Xu X-Patchwork-Id: 185252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6075493dyb; Thu, 4 Jan 2024 23:39:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDZs63u3OUvR9a1K+sMp0gwjHHlL/OFDTYvRumsV8v23wawNNXNcvRVyzfWGkEd3KctMVG X-Received: by 2002:a0d:e6c2:0:b0:5e8:7a0b:2a9c with SMTP id p185-20020a0de6c2000000b005e87a0b2a9cmr1489573ywe.89.1704440352104; Thu, 04 Jan 2024 23:39:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704440352; cv=pass; d=google.com; s=arc-20160816; b=m07ZUtAfKDYwZkby3EnHPXzO6NRqQplVSc3FjTBFQ7dWMOWdoeL9gUD4n27DYmtXys gKK60+rD4OIwsNJgugS20V1Ehay6qxCFgkfrKxLtqhiVhKBJgZItZ3oGUh5CbzcudPR3 DZXdDki2DlbVFXhw3q1OHS/UwGLRIxU/qOqZhPp6zHp+0EmfjigU2R4bFnCGlzP2TotN T+lcc8SBmt0Z8QaWOCB0eoHeSIsAZhDvPEARB1LxLBoLE4cuxSEODIgNYUH+cfuoCNGe yLyULSy/tFPqwik3jGhLQRV6DmxRGQ/xRhI5xpnLJFvJRy/vnPY5Nic0c0Rs3sGd51nd klWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=yxEcciIr2N2zoGG5cTvQw3PplwItXWySQYo9lATgUE4=; fh=w+xsGLuzpTj56E0bzPMCc39RWHkBXt2f2AGs+4pGimo=; b=fu7Noj3hMYNIx9RksMVcr6NX2Ffk90ITJHrIYHyMBaJbmMlnizNUie3zCii1HHLq6g /6laVeg8XPJveFBVO2zU9Yf8arVQp8v/bV4cCqFkxweJsRH/kKIS3omcUfd35MIOJoOG 8OsHCaJFXWExLBLID4ozrM4DdTTu3uldbNSuizqnJ5DJl2LHwMkrG8nLXNcAneV8H8ZQ dP/pYIIHRxxZ9Q4nWng0/nhvFI8YvrwF4YEuBW+XufZIV7e19b9qpDOpb/Pj4NaKwlgr OHi/qGIsLtiOIva8sRoih22bghs9Yumy0KQSAYhJJuY1Gx+eQE3RXQh0dxBiMc21Vwl5 ht2w== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f3-20020a0cf3c3000000b0067f1a03a510si1240825qvm.364.2024.01.04.23.39.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 23:39:12 -0800 (PST) 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; arc=pass (i=1); 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 B7287385801D for ; Fri, 5 Jan 2024 07:39:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 84FA3385771D for ; Fri, 5 Jan 2024 07:38:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84FA3385771D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 84FA3385771D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704440286; cv=none; b=IQ339ivk4PEa3Rb+C+eXR4RmWLKwdgxnxnEYaVFQrySn28jt9LDojXKW3eVyoBZYTFTaoo3/pM9uR77qVmGNuh74gV7F877rSmBW/H5LL7wGQHUGtLntlLg1GYO9OPXxSU8L1jqXHTCsimqPNruD0bjnZw/IUENs9M1hhELgWEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704440286; c=relaxed/simple; bh=nOXG3tdbzKwNjEDnRV54FbE9P4OsHP1A7mNV4f091Ac=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=bH+Mh+KefHxFUBzsNDwhgIYEnjVe5GjO+Q5ojDdwkAoh56h8/UUGmCbK7hIQMI1HNU9ivwHOtZGJTvOLiv1FDG7PCRGu29Vp9G4inJ9wA1m2rFeXfHNhWCStZqRcM4vH58n4yW1ewYdkVziQSwj4j6oVbk3rtDLfwrs4bH9/Hv8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLemG-0002G3-Ho for gcc-patches@gcc.gnu.org; Fri, 05 Jan 2024 02:38:04 -0500 Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8BxXevOsZdl0zsCAA--.8321S3; Fri, 05 Jan 2024 15:37:50 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axz4fLsZdlqxADAA--.7951S4; Fri, 05 Jan 2024 15:37:47 +0800 (CST) From: Jiahao Xu To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, chenglulu@loongson.cn, xuchenghua@loongson.cn, Jiahao Xu Subject: [PATCH] LoongArch: Optimize zero_extendqisi2 and zero_extendqidi2 patterns Date: Fri, 5 Jan 2024 15:37:44 +0800 Message-Id: <20240105073744.1800307-1-xujiahao@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Axz4fLsZdlqxADAA--.7951S4 X-CM-SenderInfo: 50xmxthkdrqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxCw4xKF4fCr47WFyrtFykXrc_yoWrWrykp3 y7A3y8WF1UJaySg34v9Fy3tw45GrnrGrWj9F95Xryqka17X34kXr10kr9IqFW0qa1Sqr1U WFs3uw4Uuay3JwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j1YL9UUUUU= Received-SPF: pass client-ip=114.242.206.163; envelope-from=xujiahao@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_FAIL, SPF_HELO_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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787235246326667346 X-GMAIL-MSGID: 1787235246326667346 For zero_extendqisi2 and zero_extendqidi2, use andi instead of bstrpick.w, because andi is 6 times faster than bstrpick.w. gcc/ChangeLog: * config/loongarch/loongarch.md: (zero_extend2): Rename to .. (zero_extendhi2): .. this, use hi. (zero_extendqihi2): Rename to .. (zero_extendqi2): .. this, and extend to HWD. (*zero_extend_trunc): Rename to .. (*zero_extend_trunchi): .. this, use hi. (*zero_extendhi_truncqi): Rename to .. (*zero_extend_truncqi): .. this, and extend to HWD. gcc/testsuite/ChangeLog: * gcc.target/loongarch/zeroextend-qi.c: New test. diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index d1f5b94f5d6..843dee77a60 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -397,6 +397,9 @@ ;; Likewise the 64-bit truncate-and-shift patterns. (define_mode_iterator SUBDI [QI HI SI]) +;; Scalar fixed point modes but excludes QI. +(define_mode_iterator HWD [HI SI (DI "TARGET_64BIT")]) + ;; Iterator for scalar fixed point modes. (define_mode_iterator QHWD [QI HI SI (DI "TARGET_64BIT")]) @@ -1659,48 +1662,48 @@ [(set_attr "move_type" "arith,load,load,load") (set_attr "mode" "DI")]) -(define_insn "zero_extend2" +(define_insn "zero_extendhi2" [(set (match_operand:GPR 0 "register_operand" "=r,r,r") (zero_extend:GPR - (match_operand:SHORT 1 "nonimmediate_operand" "r,m,k")))] + (match_operand:HI 1 "nonimmediate_operand" "r,m,k")))] "" "@ - bstrpick.w\t%0,%1,,0 - ld.u\t%0,%1 - ldx.u\t%0,%1" + bstrpick.w\t%0,%1,15,0 + ld.hu\t%0,%1 + ldx.hu\t%0,%1" [(set_attr "move_type" "pick_ins,load,load") (set_attr "mode" "")]) -(define_insn "zero_extendqihi2" - [(set (match_operand:HI 0 "register_operand" "=r,r,r") - (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,k,m")))] +(define_insn "zero_extendqi2" + [(set (match_operand:HWD 0 "register_operand" "=r,r,r") + (zero_extend:HWD (match_operand:QI 1 "nonimmediate_operand" "r,k,m")))] "" "@ andi\t%0,%1,0xff ldx.bu\t%0,%1 ld.bu\t%0,%1" [(set_attr "move_type" "andi,load,load") - (set_attr "mode" "HI")]) + (set_attr "mode" "")]) ;; Combiner patterns to optimize truncate/zero_extend combinations. -(define_insn "*zero_extend_trunc" +(define_insn "*zero_extend_trunchi" [(set (match_operand:GPR 0 "register_operand" "=r") (zero_extend:GPR - (truncate:SHORT (match_operand:DI 1 "register_operand" "r"))))] + (truncate:HI (match_operand:DI 1 "register_operand" "r"))))] "TARGET_64BIT" - "bstrpick.w\t%0,%1,,0" + "bstrpick.w\t%0,%1,15,0" [(set_attr "move_type" "pick_ins") (set_attr "mode" "")]) -(define_insn "*zero_extendhi_truncqi" - [(set (match_operand:HI 0 "register_operand" "=r") - (zero_extend:HI +(define_insn "*zero_extend_truncqi" + [(set (match_operand:HWD 0 "register_operand" "=r") + (zero_extend:HWD (truncate:QI (match_operand:DI 1 "register_operand" "r"))))] "TARGET_64BIT" "andi\t%0,%1,0xff" [(set_attr "alu_type" "and") - (set_attr "mode" "HI")]) + (set_attr "mode" "")]) ;; ;; .................... diff --git a/gcc/testsuite/gcc.target/loongarch/zeroextend-qi.c b/gcc/testsuite/gcc.target/loongarch/zeroextend-qi.c new file mode 100644 index 00000000000..1da8cdad2ca --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/zeroextend-qi.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler "andi" } } */ + +#include + +uint8_t +foo (uint64_t a, uint8_t b) +{ + return a + b; +}