From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1880) id 97A80384600C; Tue, 14 Jun 2022 00:30:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97A80384600C MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Max Filippov To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1081] xtensa: Make use of BALL/BNALL instructions X-Act-Checkin: gcc X-Git-Author: Takayuki 'January June' Suwa X-Git-Refname: refs/heads/master X-Git-Oldrev: e1b193c1cce3a975a9ed60dd0f30182fe0255d7c X-Git-Newrev: 70ce04ca353bb0cda8321b91a77c2477e26d339b Message-Id: <20220614003020.97A80384600C@sourceware.org> Date: Tue, 14 Jun 2022 00:30:20 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jun 2022 00:30:20 -0000 https://gcc.gnu.org/g:70ce04ca353bb0cda8321b91a77c2477e26d339b commit r13-1081-g70ce04ca353bb0cda8321b91a77c2477e26d339b Author: Takayuki 'January June' Suwa Date: Thu May 27 19:04:12 2021 +0900 xtensa: Make use of BALL/BNALL instructions In Xtensa ISA, there is no single machine instruction that calculates unary bitwise negation, but a few similar fused instructions are exist: "BALL Ax, Ay, label" // if ((~Ax & Ay) == 0) goto label; "BNALL Ax, Ay, label" // if ((~Ax & Ay) != 0) goto label; These instructions have never been emitted before, but it seems no reason not to make use of them. gcc/ChangeLog: * config/xtensa/xtensa.md (*masktrue_bitcmpl): New insn pattern. gcc/testsuite/ChangeLog: * gcc.target/xtensa/BALL-BNALL.c: New. Diff: --- gcc/config/xtensa/xtensa.md | 21 ++++++++++++++++++ gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c | 33 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 449e4b24262..a4477e2207e 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -1628,6 +1628,27 @@ (set_attr "mode" "none") (set_attr "length" "3")]) +(define_insn "*masktrue_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 "register_operand" "r")) + (const_int 0)]) + (label_ref (match_operand 2 "" "")) + (pc)))] + "" +{ + switch (GET_CODE (operands[3])) + { + case EQ: return "ball\t%0, %1, %2"; + case NE: return "bnall\t%0, %1, %2"; + default: gcc_unreachable (); + } +} + [(set_attr "type" "jump") + (set_attr "mode" "none") + (set_attr "length" "3")]) + ;; Zero-overhead looping support. diff --git a/gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c b/gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c new file mode 100644 index 00000000000..ba61c6f371b --- /dev/null +++ b/gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +extern void foo(void); + +void BNONE_test(int a, int b) +{ + if (a & b) + foo(); +} + +void BANY_test(int a, int b) +{ + if (!(a & b)) + foo(); +} + +void BALL_test(int a, int b) +{ + if (~a & b) + foo(); +} + +void BNALL_test(int a, int b) +{ + if (!(~a & b)) + foo(); +} + +/* { dg-final { scan-assembler-times "bnone" 1 } } */ +/* { dg-final { scan-assembler-times "bany" 1 } } */ +/* { dg-final { scan-assembler-times "ball" 1 } } */ +/* { dg-final { scan-assembler-times "bnall" 1 } } */