public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14848] New: [tree-ssa] prefer EQ_EXPR and NE_EXPR to ordered comparisons
@ 2004-04-04 17:28 kazu at cs dot umass dot edu
  2004-04-04 17:38 ` [Bug optimization/14848] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-04-04 17:28 UTC (permalink / raw)
  To: gcc-bugs

Consider:

void bar (unsigned int);

void
foo (unsigned int a)
{
  if (a == 0)
    if (a < 1)
      bar (a);
}

void
baz (unsigned int a)
{
  if (a < 1)
    if (a == 0)
      bar (a);
}

I get:

;; Function foo (foo)

foo (a)
{
<bb 0>:
  if (a == 0) goto <L1>; else goto <L2>; <- looks good

<L1>:;
  bar (0) [tail call];                   <- looks good

<L2>:;
  return;

}



;; Function baz (baz)

baz (a)
{
<bb 0>:
  if (a <= 0) goto <L1>; else goto <L2>;  <- a <= 0 looks ugly

<L1>:;
  bar (a) [tail call];                    <- why not bar (0)?

<L2>:;
  return;

}

We may want to prefer EQ_EXPR and NE_EXPR to ordered comparisons
whenever possible.  Among various benefits, EQ_EXPR and NE_EXPR
don't care about signedness.

Equality comparison against 0, in particular, should be no more expensive than
(unsigned) a <= 0 on most, if not all, targets.  In fact, on x86,

	testl	%eax, %eax	# 32	*cmpsi_ccno_1/1	[length = 2] <- Look!
	je	.L5	# 10	*jcc_1	[length = 2]

	cmpl	$0, %eax	# 9	*cmpsi_1_insn/1	[length = 3] <- Look!
	jbe	.L9	# 10	*jcc_1	[length = 2]

-- 
           Summary: [tree-ssa] prefer EQ_EXPR and NE_EXPR to ordered
                    comparisons
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Keywords: pessimizes-code
          Severity: enhancement
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14848


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-04-08 23:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-04 17:28 [Bug optimization/14848] New: [tree-ssa] prefer EQ_EXPR and NE_EXPR to ordered comparisons kazu at cs dot umass dot edu
2004-04-04 17:38 ` [Bug optimization/14848] " pinskia at gcc dot gnu dot org
2004-04-06 19:18 ` pinskia at gcc dot gnu dot org
2004-04-07 18:25 ` law at gcc dot gnu dot org
2004-04-08 22:53 ` law at redhat dot com
2004-04-08 23:08 ` dnovillo at redhat dot com
2004-04-08 23:16 ` pinskia at gcc dot gnu dot org

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).