public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Fei Gao <gaofei@eswincomputing.com>, gcc-patches@gcc.gnu.org
Cc: kito.cheng@gmail.com, palmer@dabbelt.com, zengxiao@eswincomputing.com
Subject: Re: [PATCH 3/5] [ifcvt] optimize x=c ? (y AND z) : y by RISC-V Zicond like insns
Date: Sun, 10 Dec 2023 22:16:48 -0700	[thread overview]
Message-ID: <25deb70e-4bc3-42a5-97f6-8597e9802c68@gmail.com> (raw)
In-Reply-To: <20231205081248.2106-3-gaofei@eswincomputing.com>



On 12/5/23 01:12, Fei Gao wrote:
> Take the following case for example.
> 
> CFLAGS: -march=rv64gc_zbb_zicond -mabi=lp64d -O2
> 
> long
> test_AND_ceqz (long x, long y, long z, long c)
> {
>    if (c)
>      x = y & z;
>    else
>      x = y;
>    return x;
> }
> 
> Before patch:
> 
> and	a2,a1,a2
> czero.eqz	a0,a2,a3
> czero.nez	a3,a1,a3
> or	a0,a3,a0
> ret
> 
> After patch:
> and	a0,a1,a2
> czero.nez	a1,a1,a3
> or	a0,a1,a0
FWIW I was having a conversation with Andrew W. a little while ago and 
his preference was to change the IOR into an ADD.  We have a better 
chance of using a compressed variant as c.add allows the full set of 
registers while c.or only allows a subset of registers.  Given one of 
the two input registers in that IOR will always have the value zero, it 
should be equivalent.

Given this is target independent code we have to be careful, but I'm not 
immediately aware of a target where using ADD would be worse than IOR 
here.   Anyway, feel free to submit a patch for that minor change, it'll 
need to queue for gcc-15, but should be non-controversial at that time.

The same trick can be done in the conditional move expander within riscv.cc.




> 
> Co-authored-by: Xiao Zeng<zengxiao@eswincomputing.com>
> 
> gcc/ChangeLog:
> 
> 	* ifcvt.cc (noce_cond_zero_binary_op_supported): Add support for AND.
>          (noce_bbs_ok_for_cond_zero_arith): Likewise.
>          (noce_try_cond_zero_arith): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/riscv/zicond_ifcvt_opt.c: add TCs for AND.
This looks fine.  I'll need to adjust the matches in the test file 
because we're not supporting SUBREGs.  I can do that easy enough.

I 3-stage bootstrapped and regression tested this on x86_64 as well as 
regression tested it in rv64gc.

I'll push it to the trunk shortly.

jeff

  reply	other threads:[~2023-12-11  5:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  8:12 [PATCH 1/5][V3][ifcvt] optimize x=c ? (y op " Fei Gao
2023-12-05  8:12 ` [PATCH 2/5] [ifcvt] optimize x=c ? (y shift_op z):y " Fei Gao
2023-12-10 20:43   ` Jeff Law
2023-12-11  4:01     ` Fei Gao
2023-12-11  6:15       ` Jeff Law
2023-12-05  8:12 ` [PATCH 3/5] [ifcvt] optimize x=c ? (y AND z) : y " Fei Gao
2023-12-11  5:16   ` Jeff Law [this message]
2023-12-05  8:12 ` [PATCH 4/5] [ifcvt] optimize x=c ? (y op const_int) " Fei Gao
2023-12-11  5:38   ` Jeff Law
2023-12-14  8:42     ` Fei Gao
2023-12-05  8:12 ` [PATCH 5/5] [ifcvt] optimize extension for x=c ? (y op z) " Fei Gao
2023-12-11  5:46   ` Jeff Law
2023-12-14  9:32     ` Fei Gao
2023-12-08  0:49 ` [PATCH 1/5][V3][ifcvt] optimize " Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25deb70e-4bc3-42a5-97f6-8597e9802c68@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gaofei@eswincomputing.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kito.cheng@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=zengxiao@eswincomputing.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).