From patchwork Fri Jul 22 11:15:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f503:0:0:0:0:0 with SMTP id q3csp188029wro; Fri, 22 Jul 2022 04:19:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vsn/4xrZ/ZRxX25AYQfZvergUhqHq8fxZHt6Xu17v7Q3tZ5YnkfYH6lOIHyiZuYKSBwv1J X-Received: by 2002:a17:906:58d1:b0:72e:e049:cf00 with SMTP id e17-20020a17090658d100b0072ee049cf00mr42872ejs.361.1658488763415; Fri, 22 Jul 2022 04:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658488763; cv=none; d=google.com; s=arc-20160816; b=NxnwmCIjm7pZksLWG0XxpLrLwaUV6kXMD8tDoBArnuW7TgadTMcp3m5dCLjMbzdye9 p5KueNpQcSTwuaMJcqFS+fQGTXad2LZ8GD3DyJAHa0VnHmpm12eaftXT5cClvOs8yehd vCbXWI0OfbJDBlPw7zj5cxbJ8dD7glkqQBK7xTmELmCBN0tWy1PIrZ7dIz6g+Nevkq6Q Cvv140AEkPXvUArOdyEgcWvxVZgGgCx4lazXFdxyi5drUWNDupmHM3gN5wQ9lb/PmGRR DfZTYj2D7YGvOUWUo1UmNMTsnSjX9KlIMlcIbPJ9RIlVLzGY5H8U2v2JrzLiafxgvwvd zV6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=y+j6iy3mNfloph41S/gGHq68vMO//kHX7OgEmDy0ecU=; b=bQNSymcv4eojrhQiDKGy1YLgh3gChZ7jEMNICO1VBgKarNRppqZ2N8yc1yOli3bdn3 Z3431zV2u7zeWRAaaW4hqYjUJeSpNln5gpjvuCCsfzOcwhziIJuxe2ce5bXducCyCFSF nZTEE2M45YikxUpKdFa2IDGpiyZuyc4Eq9wCjhX5Fy6Q14/BNzwmngLbpVguATwHlAdq 7c6hGRPG0RG853HTnRt1rBHdE/5/DAQt2yypS4uIm9wDMkYcHgZm6kdsoBZiyZ5MytVg qociO8dF0ULxAQIGFtD+X2zKvatkbh20MXy62VAQYFAKxIajhNYLxgB/TPakDDVxeEL6 7GsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LqDa1Q1i; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e12-20020a056402190c00b0043bc4b3aa3fsi6138129edz.443.2022.07.22.04.19.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 04:19:23 -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=pass header.i=@gcc.gnu.org header.s=default header.b=LqDa1Q1i; 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"; 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 D8C103835404 for ; Fri, 22 Jul 2022 11:19:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8C103835404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658488757; bh=y+j6iy3mNfloph41S/gGHq68vMO//kHX7OgEmDy0ecU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LqDa1Q1iiLIRFl2D9/Xgqm/aFgjIQ8Cuu3W+soV75NFerQLTdGcT/7rLWF8uMUPxG m3Tr/Wc9So0Ab2a9wiqOChBHXJHQYI0XIEYyFX3CfDGEk18BZ/DN0fqT+jwed0e+Xi IIEtYwIykkuhCEeEikiZMZM3mSAUCurVd22IBbnE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh603-vm0.bullet.mail.ssk.yahoo.co.jp (nh603-vm0.bullet.mail.ssk.yahoo.co.jp [182.22.90.41]) by sourceware.org (Postfix) with SMTP id CB0FB3857C5D for ; Fri, 22 Jul 2022 11:18:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB0FB3857C5D Received: from [182.22.66.104] by nh603.bullet.mail.ssk.yahoo.co.jp with NNFMP; 22 Jul 2022 11:18:28 -0000 Received: from [182.22.91.129] by t602.bullet.mail.ssk.yahoo.co.jp with NNFMP; 22 Jul 2022 11:18:28 -0000 Received: from [127.0.0.1] by omp602.mail.ssk.yahoo.co.jp with NNFMP; 22 Jul 2022 11:18:28 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 469658.81223.bm@omp602.mail.ssk.yahoo.co.jp Received: (qmail 19866 invoked by alias); 22 Jul 2022 11:18:28 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.182 with ) by smtp5008.mail.kks.ynwp.yahoo.co.jp with SMTP; 22 Jul 2022 11:18:28 -0000 X-YMail-JAS: 0.Y5QzsVM1nkse5Tds.iOXFD4oqt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Xl7wKIkmG5aq Lrv4O Message-ID: <7b69b20d-784a-925c-52f4-32c2a6b18ab1@yahoo.co.jp> Date: Fri, 22 Jul 2022 20:15:50 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0.3 Content-Language: en-US To: GCC Patches Subject: [PATCH] xtensa: Optimize "bitwise AND NOT with imm" followed by "branch if (not) equal to zero" X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Takayuki 'January June' Suwa 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?1739051513909524163?= X-GMAIL-MSGID: =?utf-8?q?1739051513909524163?= The RTL combiner will transform "if ((x & C) == C) goto label;" into "if ((~x & C) == 0) goto label;" and will try to match it with the insn patterns. /* example */ void test_0(int a) { if ((char)a == 255) foo(); } void test_1(int a) { if ((unsigned short)a == 0xFFFF) foo(); } void test_2(int a) { if ((a & 0x00003F80) != 0x00003F80) foo(); } ;; before test_0: extui a2, a2, 0, 8 movi a3, 0xff bne a2, a3, .L1 j.l foo, a9 .L1: ret.n test_1: movi.n a3, -1 extui a2, a2, 0, 16 extui a3, a3, 16, 16 bne a2, a3, .L3 j.l foo, a9 .L3: ret.n test_2: movi a3, 0x80 extui a2, a2, 7, 7 addmi a3, a3, 0x3f00 slli a2, a2, 7 beq a2, a3, .L5 j.l foo, a9 .L5: ret.n ;; after test_0: movi a3, 0xff bnall a2, a3, .L1 j.l foo, a9 .L1: ret.n test_1: movi.n a3, -1 extui a3, a3, 16, 16 bnall a2, a3, .L3 j.l foo, a9 .L3: ret.n test_2: movi a3, 0x80 addmi a3, a3, 0x3f00 ball a2, a3, .L5 j.l foo, a9 .L5: ret.n gcc/ChangeLog: * config/xtensa/xtensa.md (*masktrue_const_bitcmpl): Add a new insn_and_split pattern, and a few split patterns for spacial cases. --- gcc/config/xtensa/xtensa.md | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index c02f1a56641..899ce2755aa 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -1714,6 +1714,90 @@ (set_attr "mode" "none") (set_attr "length" "3")]) +(define_insn_and_split "*masktrue_const_bitcmpl" + [(set (pc) + (if_then_else (match_operator 3 "boolean_operator" + [(and:SI (not:SI (match_operand:SI 0 "register_operand" "r")) + (match_operand:SI 1 "const_int_operand" "i")) + (const_int 0)]) + (label_ref (match_operand 2 "" "")) + (pc)))] + "exact_log2 (INTVAL (operands[1])) < 0" + "#" + "&& can_create_pseudo_p ()" + [(set (match_dup 4) + (match_dup 1)) + (set (pc) + (if_then_else (match_op_dup 3 + [(and:SI (not:SI (match_dup 0)) + (match_dup 4)) + (const_int 0)]) + (label_ref (match_dup 2)) + (pc)))] +{ + operands[4] = gen_reg_rtx (SImode); +} + [(set_attr "type" "jump") + (set_attr "mode" "none") + (set (attr "length") + (if_then_else (match_test "TARGET_DENSITY + && IN_RANGE (INTVAL (operands[1]), -32, 95)") + (const_int 5) + (if_then_else (match_test "xtensa_simm12b (INTVAL (operands[1]))") + (const_int 6) + (const_int 10))))]) + +(define_split + [(set (pc) + (if_then_else (match_operator 2 "boolean_operator" + [(subreg:HQI (not:SI (match_operand:SI 0 "register_operand")) 0) + (const_int 0)]) + (label_ref (match_operand 1 "")) + (pc)))] + "!BYTES_BIG_ENDIAN" + [(set (pc) + (if_then_else (match_op_dup 2 + [(and:SI (not:SI (match_dup 0)) + (match_dup 3)) + (const_int 0)]) + (label_ref (match_dup 1)) + (pc)))] +{ + operands[3] = GEN_INT ((1 << GET_MODE_BITSIZE (mode)) - 1); +}) + +(define_split + [(set (pc) + (if_then_else (match_operator 2 "boolean_operator" + [(subreg:HI (not:SI (match_operand:SI 0 "register_operand")) 2) + (const_int 0)]) + (label_ref (match_operand 1 "")) + (pc)))] + "BYTES_BIG_ENDIAN" + [(set (pc) + (if_then_else (match_op_dup 2 + [(and:SI (not:SI (match_dup 0)) + (const_int 65535)) + (const_int 0)]) + (label_ref (match_dup 1)) + (pc)))]) + +(define_split + [(set (pc) + (if_then_else (match_operator 2 "boolean_operator" + [(subreg:QI (not:SI (match_operand:SI 0 "register_operand")) 3) + (const_int 0)]) + (label_ref (match_operand 1 "")) + (pc)))] + "BYTES_BIG_ENDIAN" + [(set (pc) + (if_then_else (match_op_dup 2 + [(and:SI (not:SI (match_dup 0)) + (const_int 255)) + (const_int 0)]) + (label_ref (match_dup 1)) + (pc)))]) + (define_insn_and_split "*masktrue_const_pow2_minus_one" [(set (pc) (if_then_else (match_operator 4 "boolean_operator"