From patchwork Thu Jan 4 01:58:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 184892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5370868dyb; Wed, 3 Jan 2024 18:01:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrZBToDoyS0XqRjIxwrJVelWdRiy+qmifX8HmHJMvYEweLDHn/7tpfA2mifT8NCVMdf/tc X-Received: by 2002:a05:6214:d69:b0:67f:76ef:48f6 with SMTP id 9-20020a0562140d6900b0067f76ef48f6mr20054770qvs.47.1704333660832; Wed, 03 Jan 2024 18:01:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704333660; cv=pass; d=google.com; s=arc-20160816; b=qihiUABZufIcap8NGbwF6blWWrQneToqEhXsAmhT0enut6UZ4sghsNDkbsmdADTpN5 mkqlyrwEwYTrTWRps962L8cL9PHCTt9OrsGBUbcsy23qQk5j8JZOBT+0WM4hJ2AlKMkN /9MM5+WyNOQ/IiPnMKHx3HXg2kHs59H0EvktTTmBbmXZW1mwIVUceEveikZm6COqRnES xMrNeJ9XB5x0s3E3SDBwCvM68JcXWGFDwxWNcz6CQRtbzVi4BhJA9q4LYv1OrctRjcOM 6IQZjMtWuJV9LQJAY0gV7UovWPm77n5isIKFBjmEm0ZLCw4CJOLPqADJl8w1HrW4iJbn X2rw== 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:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=V4ws+u9Nc8v3SjweHT4FPHU+7NfiVyl5tGYcuDS+FkY=; fh=Yb7vMu1xmO3w7lzcUJ3g87/936eZQp4GM8b6tTP+qWg=; b=btvBwi7tUP35RuudgZh9PwbvKdxwFo8Ji7MVGI9VKpHU/4L7hkCBDG9kIleSHNezK/ SDgirym+L8TUyQuzTo5Uespxpgq42dzs2IvuHJyA4+L9T0wM0y8R7l34VzuGhUedPVVd baMLjg8LT7lM2tavTnlATTCrxqh90AxO0f+/nbxdl0ub8sF6yKgMQ3ei0TtDarP2itdw HxvpKjGTEA9kHAFIq+ifjNnywK4B5ZjwBwzouRhhlnK7OqTDow840VoKvEM53XxkkA92 ovRDccjAsIZaqCzcGae/78aLg70Y3q7nsCvz7dh72d3NcIdKPSpfhsDS39KnUPdz1aZN VGEQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TYKsjc+t; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 z4-20020a0cda84000000b0067f8809bf34si30005408qvj.537.2024.01.03.18.01.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 18:01:00 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TYKsjc+t; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A7FB3858C39 for ; Thu, 4 Jan 2024 02:01:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A7FB3858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704333660; bh=V4ws+u9Nc8v3SjweHT4FPHU+7NfiVyl5tGYcuDS+FkY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TYKsjc+tQLPzFTa+T0zHvfFxIoJN0qhbSYz1yadpswS4lr4ViQUt4KfF3N/oKb7Xg MZtdHJv7pOCRsATCvWCXg6Ws0D3dHfdTzJNhZY2i8obdBvhWXxi11Ai5J9XCQ6l7iL KSoLkohwU/LTe1Y2q4uYFR5f4khB2Uosb92H8lRI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by sourceware.org (Postfix) with ESMTPS id E808F3858284; Thu, 4 Jan 2024 01:58:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E808F3858284 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E808F3858284 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704333532; cv=none; b=hx6qp27wJXhlSHDpmJ6xe7ljxfdh62a0o/n8QCYwFQMnakOeK+PGoENJKHPVxlgfHlPeN5l4OW0jAm2Klhucd+wruWWsFIRvdNt5MV6+IPaFOIabSoWrVrUekJp3fQ6av7Gd4wV90f77/8bEwEioa+CkMCXO/J65TGow5PrVVDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704333532; c=relaxed/simple; bh=msoYjCwRT7A6J+GZnMM7RZ08iiYW5fX69WhmrIcj/MQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=nZQK8fXBWisq/j8X3eX817wJnaKHYISlRMK6uAJqkxfLK0HFbR8S33TwdiN9toflXcGTPXBEMft4hJ/WJVI+vaRBFKX2v9bQGaaRxj9cH1dI1pqsEQ7bz1YFFkTMamBIM4NtbEEGemHVHkhVcw0s71ufJjMl+hMH1wbA3DFew0g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d3ed1ca402so169185ad.2; Wed, 03 Jan 2024 17:58:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704333526; x=1704938326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V4ws+u9Nc8v3SjweHT4FPHU+7NfiVyl5tGYcuDS+FkY=; b=cXN5HLEnclGPL3WdlPJ/qFYDuSAZrNzOlepuhkcDWTxHUQEz0aUAMxe56a8dJvrIzl SsqOMCy/6S+kwgmVlFl76+JL/Qrh9eA6LGRfgtP0vlKG0kqq2KrCofpyQ9jFv2cxt9Gu AOijGUqVSjnJ0fqC6lWCmR+tishNKRkrQGQCfj1JRAU6JNDhgTzuMj9LlJ0Z7srmHveH dGcIslXQBpZ5ktWHuhVTcAsnanlSlCtU2V/fHCANMdqlvTWhsFXJ+hT2VDuNQUR8rR08 jQwbuJEhxM71cB4YqnysJeOrZNynxru8F2Y/loexfU9o77y2UG6/m6hvEeihtEY/lYeF VxHQ== X-Gm-Message-State: AOJu0YyOkROYMEdoqg+D4y+d6tqIuKxCDkks7MFDgZmnr2hErRs5H+sa Exdx0GOdwu1BgkzxmQhxVN+/+jNJfXUeFw== X-Received: by 2002:a17:902:e541:b0:1d3:ac23:b511 with SMTP id n1-20020a170902e54100b001d3ac23b511mr26453974plf.54.1704333526497; Wed, 03 Jan 2024 17:58:46 -0800 (PST) Received: from localhost.localdomain ([149.248.38.156]) by smtp.gmail.com with ESMTPSA id e6-20020a170902744600b001d4b0ae7052sm7028122plt.135.2024.01.03.17.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 17:58:45 -0800 (PST) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: YunQiang Su Subject: [committed] MIPS: Add pattern insqisi_extended and inshisi_extended Date: Thu, 4 Jan 2024 09:58:18 +0800 Message-Id: <20240104015819.353901-3-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104015819.353901-1-syq@gcc.gnu.org> References: <20240104015819.353901-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.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: 1787123373015991831 X-GMAIL-MSGID: 1787123373015991831 This match pattern allows combination (zero_extract:DI 8, 24, QI) with an sign-extend to 32bit INS instruction on TARGET_64BIT. For SI mode, if the sign-bit is modified by bitops, we will need a sign-extend operation. Since 32bit INS instruction can be sure that result is sign-extended, and the QImode src register is safe for INS, too. (insn 19 18 20 2 (set (zero_extract:DI (reg/v:DI 200 [ val ]) (const_int 8 [0x8]) (const_int 24 [0x18])) (subreg:DI (reg:QI 205) 0)) "../xx.c":7:29 -1 (nil)) (insn 20 19 23 2 (set (reg/v:DI 200 [ val ]) (sign_extend:DI (subreg:SI (reg/v:DI 200 [ val ]) 0))) "../xx.c":7:29 -1 (nil)) Combine try to merge them to: (insn 20 19 23 2 (set (reg/v:DI 200 [ val ]) (sign_extend:DI (ior:SI (and:SI (subreg:SI (reg/v:DI 200 [ val ]) 0) (const_int 16777215 [0xffffff])) (ashift:SI (subreg:SI (reg:QI 205 [ MEM[(const unsigned char *)buf_8(D) + 3B] ]) 0) (const_int 24 [0x18]))))) "../xx.c":7:29 18 {*insv_extended} (expr_list:REG_DEAD (reg:QI 205 [ MEM[(const unsigned char *)buf_8(D) + 3B] ]) (nil))) And do similarly for 16/16 pair: (insn 13 12 14 2 (set (zero_extract:DI (reg/v:DI 198 [ val ]) (const_int 16 [0x10]) (const_int 16 [0x10])) (subreg:DI (reg:HI 201 [ MEM[(const short unsigned int *)buf_6(D) + 2B] ]) 0)) "xx.c":5:30 286 {*insvdi} (expr_list:REG_DEAD (reg:HI 201 [ MEM[(const short unsigned int *)buf_6(D) + 2B] ]) (nil))) (insn 14 13 17 2 (set (reg/v:DI 198 [ val ]) (sign_extend:DI (subreg:SI (reg/v:DI 198 [ val ]) 0))) "xx.c":5:30 241 {extendsidi2} (nil)) ------------> (insn 14 13 17 2 (set (reg/v:DI 198 [ val ]) (sign_extend:DI (ior:SI (ashift:SI (subreg:SI (reg:HI 201 [ MEM[(const short unsigned int *)buf_6(D) + 2B] ]) 0) (const_int 16 [0x10])) (zero_extend:SI (subreg:HI (reg/v:DI 198 [ val ]) 0))))) "xx.c":5:30 284 {*inshisi_extended} (expr_list:REG_DEAD (reg:HI 201 [ MEM[(const short unsigned int *)buf_6(D) + 2B] ]) (nil))) Let's accept these patterns, and set the cost to 1 instruction. gcc PR rtl-optimization/104914 * config/mips/mips.md (insqisi_extended): New patterns. (inshisi_extended): Ditto. gcc/testsuite * gcc.target/mips/pr104914.c: New test. --- gcc/config/mips/mips.md | 24 +++++++++++++++++++++++ gcc/testsuite/gcc.target/mips/pr104914.c | 25 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/gcc.target/mips/pr104914.c diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index e1762ce105b..17dfcbd6722 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -4419,6 +4419,30 @@ (define_insn "*extzv_truncsi_exts" [(set_attr "type" "arith") (set_attr "mode" "SI")]) +(define_insn "*insqisi_extended" + [(set (match_operand:DI 0 "register_operand" "=d") + (sign_extend:DI + (ior:SI (and:SI (subreg:SI (match_dup 0) 0) + (const_int 16777215)) + (ashift:SI + (subreg:SI (match_operand:QI 1 "register_operand" "d") 0) + (const_int 24)))))] + "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXT_INS" + "ins\t%0,%1,24,8" + [(set_attr "mode" "SI") + (set_attr "perf_ratio" "1")]) + +(define_insn "*inshisi_extended" + [(set (match_operand:DI 0 "register_operand" "=d") + (sign_extend:DI + (ior:SI + (ashift:SI (subreg:SI (match_operand:HI 1 "register_operand" "d") 0) + (const_int 16)) + (zero_extend:SI (subreg:HI (match_dup 0) 0)))))] + "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXT_INS" + "ins\t%0,%1,16,16" + [(set_attr "mode" "SI") + (set_attr "perf_ratio" "1")]) (define_expand "insvmisalign" [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand") diff --git a/gcc/testsuite/gcc.target/mips/pr104914.c b/gcc/testsuite/gcc.target/mips/pr104914.c new file mode 100644 index 00000000000..5dd10e84c17 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/pr104914.c @@ -0,0 +1,25 @@ +/* { dg-do run } */ +/* { dg-options "-mabi=64" } */ + +extern void abort (void); +extern void exit (int); + +NOMIPS16 int test (const unsigned char *buf) +{ + int val; + ((unsigned char*)&val)[0] = *buf++; + ((unsigned char*)&val)[1] = *buf++; + ((unsigned char*)&val)[2] = *buf++; + ((unsigned char*)&val)[3] = *buf++; + if(val > 0) + return 1; + else + return 0; +} + +int main () +{ + if (test("\xff\xff\xff\xff") != 0) + abort(); + exit(0); +}