From patchwork Sun May 29 10:46:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 54486 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DE173838221 for ; Sun, 29 May 2022 11:02:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DE173838221 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1653822151; bh=xwpmSrOs4irzb+6jAOYjdrpQ/a0AB2PCDw801dYPsrY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=muR+PVLeMYFpURH+xEF/Y9zT8wa0G0lw1/hUsur0qGAXE3VX/icf6juH3LGbShpk/ 1vD1HQWtGSTg1qc0h8PzsFTAo4rgLFJXW0RgDro7bdD9X5R3y+Iiw3nyLPijl29iPI EQPIdPCPdW8RMCUpQ4ZG3u1u70ffTOM9HhPAwYdY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh602-vm9.bullet.mail.ssk.yahoo.co.jp (nh602-vm9.bullet.mail.ssk.yahoo.co.jp [182.22.90.34]) by sourceware.org (Postfix) with SMTP id E38003856264 for ; Sun, 29 May 2022 11:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E38003856264 Received: from [182.22.66.103] by nh602.bullet.mail.ssk.yahoo.co.jp with NNFMP; 29 May 2022 11:00:05 -0000 Received: from [182.22.91.128] by t601.bullet.mail.ssk.yahoo.co.jp with NNFMP; 29 May 2022 11:00:05 -0000 Received: from [127.0.0.1] by omp601.mail.ssk.yahoo.co.jp with NNFMP; 29 May 2022 11:00:05 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 191239.85783.bm@omp601.mail.ssk.yahoo.co.jp Received: (qmail 74216 invoked by alias); 29 May 2022 11:00:05 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.170 with ) by smtp5001.mail.kks.ynwp.yahoo.co.jp with SMTP; 29 May 2022 11:00:04 -0000 X-YMail-JAS: ncvXB38VM1mXteI.8T.pshK6AKOH7haNZYShuANc0OO4YncUBXwJpnuB3Sr9IZH9kpEbn7eIyMKITYLEKFPWKirLLt.GkefhOcT0TnpNbMi_QzyZKs9PziGQQzJI.1A3Pm3opUu3Bw-- X-Apparently-From: X-YMail-OSG: mFfjS10VM1ngnBTI0HOAzQ04.aNKsUmZej5XxKMMczwpPi3 KYZor6_lJqakjAePzejVRJsnRmDsCUEb2XB5b6RptP2VNwI0v4rh8sV5hmGt 0maKGDTR1OWbVQvoYaPlZCyhHguC0n9EIlax.T6LVDQngKphZdOmMG0c2X6p BzPfDGIBAwOwDJxuY5mboosEctXjkMV7H8wIW.KWIi9VOYjYdY.VqsZzi_Ce ooAKtwTLKmthmdbRLLRspUjOWRi2SCfpiV1CbST_.iWHeW6ZFi1L2DICGNZB BV90wCwKliWIxNUFBJWKATedDUxqxz8HzWJISoe4Wz_4IU2kOESk7hU05Vq1 AC1HEyC0i.ilC6FygiBeSMHXJ1KQvzAPvGHnwDp2p_YgKVhkKuGSGqyh5jpc EXnx5hE_9wPvL0DKknHJxSs8wLay2LylMrbSm8_ed49OP.3CL0LXueoyHX_4 Om0TlWBUozObvXUT_g2n_Jgj5OELMz6zKNwxdqRXX1UHIotN6yfqaFAutLiP FtbjEPt9odo9GeWVudvtVylAHbbxgK6IknnYpZSh2luwAJq4C12YJDeLkbX7 Wwcgx__in2KRh9KEI_cHs5zjlTcUExmZFJpJAM1.ItcnWUquWTIrX.n8K3wH fW0B7YhMGn7T7ki4xctS2AwxN3m1ugaCn15N_hi2QKZQmlrkcWkaastYqDFQ a1MPzRRyTjuUYuEtwt5bgE4qpjPprc3W4S1ZAxLlrbK_4OothIL67gfJK0fr cYQIDtAjloywwQcmq7pt6vwWTYIcZHGfTd8f3hluD4W4JKujsvp.sEZNM_PO a6tfAGlyET.Q9MxSqG.k9L_ORVfaS6Q.RHhnI7A9zF7QGyE10MeG9a20Y3j2 SnfbRh4wNLu1ZsoewaR3UD5_rCOZsbSJfEUhSmWkpD4nxiVx3ZKMg9D39IF5 .SET8OFR_u__VToHsNA-- Message-ID: <9835da53-f201-fe51-c9a5-dcf9d7297941@yahoo.co.jp> Date: Sun, 29 May 2022 19:46:16 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: GCC Patches Subject: [PATCH 2/4] xtensa: Make one_cmplsi2 optimizer-friendly X-Spam-Status: No, score=-12.6 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" In Xtensa ISA, there is no single machine instruction that calculates unary bitwise negation. But a few optimizers assume that bitwise negation can be done by a single insn. As a result, '((x < 0) ? ~x : x)' cannot be optimized to '(x ^ (x >> 31))' ever before, for example. This patch relaxes such limitation, by putting the insn expansion off till the split pass. gcc/ChangeLog: * config/xtensa/xtensa.md (one_cmplsi2): Rearrange as an insn_and_split pattern. gcc/testsuite/ChangeLog: * gcc.target/xtensa/one_cmpl_abs.c: New. --- gcc/config/xtensa/xtensa.md | 26 +++++++++++++------ .../gcc.target/xtensa/one_cmpl_abs.c | 9 +++++++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.target/xtensa/one_cmpl_abs.c diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 217879bde15..f11ae4910f8 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -556,16 +556,26 @@ (set_attr "mode" "SI") (set_attr "length" "3")]) -(define_expand "one_cmplsi2" - [(set (match_operand:SI 0 "register_operand" "") - (not:SI (match_operand:SI 1 "register_operand" "")))] +(define_insn_and_split "one_cmplsi2" + [(set (match_operand:SI 0 "register_operand" "=a") + (not:SI (match_operand:SI 1 "register_operand" "r")))] "" + "#" + "&& can_create_pseudo_p ()" + [(set (match_dup 2) + (const_int -1)) + (set (match_dup 0) + (xor:SI (match_dup 1) + (match_dup 2)))] { - rtx temp = gen_reg_rtx (SImode); - emit_insn (gen_movsi (temp, constm1_rtx)); - emit_insn (gen_xorsi3 (operands[0], temp, operands[1])); - DONE; -}) + operands[2] = gen_reg_rtx (SImode); +} + [(set_attr "type" "arith") + (set_attr "mode" "SI") + (set (attr "length") + (if_then_else (match_test "TARGET_DENSITY") + (const_int 5) + (const_int 6)))]) (define_insn "negsf2" [(set (match_operand:SF 0 "register_operand" "=f") diff --git a/gcc/testsuite/gcc.target/xtensa/one_cmpl_abs.c b/gcc/testsuite/gcc.target/xtensa/one_cmpl_abs.c new file mode 100644 index 00000000000..608f65fd777 --- /dev/null +++ b/gcc/testsuite/gcc.target/xtensa/one_cmpl_abs.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O1" } */ + +int one_cmpl_abs(int a) +{ + return a < 0 ? ~a : a; +} + +/* { dg-final { scan-assembler-not "bgez" } } */