public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@redhat.com>
To: Ian Lance Taylor <ian@wasabisystems.com>
Cc: gcc@gcc.gnu.org, gcc-bugzilla@gcc.gnu.org
Subject: Re: gcc/1532: Redundant compare instructions on i386
Date: Wed, 21 Jan 2004 00:47:00 -0000	[thread overview]
Message-ID: <20040120164659.C25326@redhat.com> (raw)
In-Reply-To: <m3ptdemh4o.fsf@gossamer.airs.com>; from ian@wasabisystems.com on Tue, Jan 20, 2004 at 04:42:31PM -0500

On Tue, Jan 20, 2004 at 04:42:31PM -0500, Ian Lance Taylor wrote:
> So I punted and wrote a quick pass in machine dependent reorg to
> eliminate obvious duplicate comparison cases.  It works fine on this
> test case--the resulting code is the same except that the redudant
> comparison is eliminated.  But it kind of sucks because it doesn't do
> any real dataflow analysis, so it will miss all but the most obvious
> cases.

This is actually not bad, I think, simply because almost everything
clobbers the flags, and therefore data can't flow very far at all.

About the only thing you could do better than what you did is to
follow extended basic blocks.  I.e. follow jumps forward through
jumps to blocks with only one incoming edge.

> 1) Comparisons are represented with different modes for purposes of
>    permitting future optimization, but are otherwise implemented by
>    the same underlying instruction.

This isn't really correct.  Lots of instructions set *some* flags
bits, but not all instructions set all flags bits in useful ways.
The different modes describe how the flags will be used, and thus
constrain which insns may be used to generate the flags.  This is
most apparent when you look at the combination patterns that do
add+compare and the like.

> 3) We want the compiler to eliminate obvious duplication in setting
>    the comparison flags.  That is, the compiler should recognize when
>    one compare instruction will produce the same result as a previous
>    compare instruction.
>    a) It should do this despite any mode differences.
>    b) It should do this even though the result goes to a hard
>       register.
>    c) It should not do this in the usual GCSE way, which involves
>       copying the value to a pseudo-register, because if that
>       pseudo-register is used after eflags has been clobbered the
>       resulting code will almost certainly be worse.

Agreed.

> There is some other awful code in this test case which I haven't even
> looked at yet, a useless jump to the next instruction:
> 
> 	je	.L1
> .L2:
> .L1:
> 
> I assume that is a separate problem, probably related to inlining.

I would assume.  Not sure exactly what would cause that...
It's possible there's something in the rtl between L2 and L1
seen by the optimizers but which produces no assembly.  If
so, there's probably not much to fix there.


r~

  reply	other threads:[~2004-01-21  0:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-20 21:42 Ian Lance Taylor
2004-01-21  0:47 ` Richard Henderson [this message]
2004-01-21  3:24   ` Ian Lance Taylor
2004-01-21  5:34     ` law
2004-01-21  6:32     ` law
2004-01-21  7:48       ` Richard Henderson
2004-01-21  8:47         ` law
2004-01-22  3:39 ` Jamie Lokier
2004-01-22  6:27 ` Segher Boessenkool

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=20040120164659.C25326@redhat.com \
    --to=rth@redhat.com \
    --cc=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=ian@wasabisystems.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).