public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: "Koning, Paul" <Paul.Koning@dell.com>
Cc: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Remove CC0
Date: Thu, 27 May 2021 17:19:40 -0500	[thread overview]
Message-ID: <20210527221940.GA3085@gate.crashing.org> (raw)
In-Reply-To: <6CECF8F7-5271-4C77-955A-9915EB6075B7@dell.com>

Hi!

Whoops, I forgot to reply to this...

On Wed, May 05, 2021 at 06:25:49PM +0000, Koning, Paul wrote:
> > void g(void);
> > void h(void);
> > void i(void);
> > void f(long a, long b)
> > {
> >        if (a < b)
> >                g();
> >        if (a == b)
> >                h();
> >        if (a > b)
> >                i();
> > }
> 
> FWIW, that also works on pdp11, so it seems the general mechanism is in place and working.  Well, with one oddity, an unnecessary third conditional branch:
> 
> _f:
> 	mov	02(sp),r1
> 	mov	04(sp),r0
> 	cmp	r1,r0
> 	blt	L_7
> 	beq	L_4
> 	bgt	L_5
> 	rts	pc
> L_5:
> 	jsr	pc,_i
> 	rts	pc
> L_4:
> 	jsr	pc,_h
> 	rts	pc
> L_7:
> 	jsr	pc,_g
> 	rts	pc

We have that on PowerPC as well (-m32 because it is shorter code with
fewer distractions):

f:
        cmpw 0,3,4
        blt 0,.L9
        beq 0,.L3
        blelr 0
        b i
        .p2align 4,,15
.L3:
        b h
        .p2align 4,,15
.L9:
        b g

The "blelr" (branch to LR if less than or equal) can never be taken.
This is there in the Gimple already:

===
void f (long int a, long int b)
{
;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  if (a_4(D) < b_5(D))
    goto <bb 3>; [33.00%]
  else
    goto <bb 4>; [67.00%]
;;    succ:       3
;;                4

;;   basic block 3, loop depth 0
;;    pred:       2
  g (); [tail call]
  goto <bb 8>; [100.00%]
;;    succ:       8

;;   basic block 4, loop depth 0
;;    pred:       2
  if (a_4(D) == b_5(D))
    goto <bb 6>; [30.21%]
  else
    goto <bb 5>; [69.79%]
;;    succ:       6
;;                5

;;   basic block 5, loop depth 0
;;    pred:       4
  if (a_4(D) > b_5(D))
    goto <bb 7>; [70.57%]
  else
    goto <bb 8>; [29.43%]
;;    succ:       7
;;                8

;;   basic block 6, loop depth 0
;;    pred:       4
  h (); [tail call]
  goto <bb 8>; [100.00%]
;;    succ:       8

;;   basic block 7, loop depth 0
;;    pred:       5
  i (); [tail call]
;;    succ:       8

;;   basic block 8, loop depth 0
;;    pred:       5
;;                7
;;                6
;;                3
  return;
;;    succ:       EXIT

}
===

So, it also exists in the RTL -- and it isn't optimised away later.
That would be quite hard to do in fact, and if it is handled in Gimple
all will be fine, and it should be much easier to do in Gimple.

Can you open a PR please?


Segher

  reply	other threads:[~2021-05-27 22:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 22:55 Segher Boessenkool
2021-05-04  8:44 ` Richard Biener
2021-05-04 13:45   ` Segher Boessenkool
2021-05-04 15:08 ` Richard Earnshaw
2021-05-04 16:22   ` Eric Botcazou
2021-05-04 16:24     ` Richard Earnshaw
2021-05-05 12:45   ` Segher Boessenkool
2021-05-05 18:25     ` Koning, Paul
2021-05-27 22:19       ` Segher Boessenkool [this message]
2021-05-27 19:58 ` H.J. Lu
2021-05-27 22:28   ` Segher Boessenkool
2021-05-28  4:20     ` 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=20210527221940.GA3085@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=Paul.Koning@dell.com \
    --cc=Richard.Earnshaw@foss.arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).