public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/17931] New: andl and testb are not combined
@ 2004-10-11 13:52 kazu at cs dot umass dot edu
  2004-10-11 13:54 ` [Bug rtl-optimization/17931] " kazu at cs dot umass dot edu
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-11 13:52 UTC (permalink / raw)
  To: gcc-bugs

Consider:

struct flags {
  unsigned f0 : 1;
  unsigned f1 : 1;
};

_Bool
foo (struct flags *p)
{
  if (p->f0)
    return 1;

  return p->f1;
}

With "cc1 -O2 -fomit-frame-pointer", I get

foo:
	movl	4(%esp), %eax
	movb	(%eax), %dl
	movb	%dl, %al
	andl	$1, %eax
	testb	%al, %al
	jne	.L7
	xorl	%eax, %eax
	testb	$2, %dl
	setne	%al
	ret
	.p2align 2,,3
.L7:
	movl	$1, %eax
	ret

Note that andl and testb are not combined to "testb $1, %al".
If they were combined, we would not destroy %eax,
so we would not need to make a copy of %al for a later use.

With -march=pentium4 or -march=athlon-xp, I get a similar result.

-- 
           Summary: andl and testb are not combined
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: rtl-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
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug rtl-optimization/17931] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
@ 2004-10-11 13:54 ` kazu at cs dot umass dot edu
  2004-10-11 14:01 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-11 13:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-10-11 13:54 -------
Actually, we don't need "movl $1, %eax" at the end, either.


-- 


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


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

* [Bug rtl-optimization/17931] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
  2004-10-11 13:54 ` [Bug rtl-optimization/17931] " kazu at cs dot umass dot edu
@ 2004-10-11 14:01 ` pinskia at gcc dot gnu dot org
  2004-10-11 14:06 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-11 14:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-11 14:01 -------
Confirmed, combine does not simplify:
(insn 14 13 15 0 (parallel [
            (set (reg:QI 64)
                (and:QI (reg:QI 63)
                    (const_int 1 [0x1])))
            (clobber (reg:CC 17 flags))
        ]) 206 {*andqi_1} (insn_list:REG_DEP_TRUE 13 (nil))
    (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))

(insn 15 14 16 0 (set (reg:CCZ 17 flags)
        (compare:CCZ (reg:QI 64)
            (const_int 0 [0x0]))) 6 {*cmpqi_ccno_1} (insn_list:REG_DEP_TRUE 14 (nil))
    (expr_list:REG_DEAD (reg:QI 64)
        (nil)))

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-11 14:01:46
               date|                            |


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


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

* [Bug rtl-optimization/17931] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
  2004-10-11 13:54 ` [Bug rtl-optimization/17931] " kazu at cs dot umass dot edu
  2004-10-11 14:01 ` pinskia at gcc dot gnu dot org
@ 2004-10-11 14:06 ` pinskia at gcc dot gnu dot org
  2004-10-11 14:12 ` [Bug rtl-optimization/17931] [4.0 Regresion] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-11 14:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-11 14:06 -------
Note PPC's resulting asm is so much better:
        lwz r3,0(r3)
        li r0,1
        cmpwi cr7,r3,0
        blt- cr7,L4
        rlwinm r0,r3,2,31,31
L4:
        mr r3,r0
        blr

But can be improved still down to (but that is a register allocator problem):
        lwz r0,0(r3)
        cmpwi cr7,r0,0
        li r3,1
        bltlr- cr7
        rlwinm r3,r0,2,31,31
        blr

-- 


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


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

* [Bug rtl-optimization/17931] [4.0 Regresion] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
                   ` (2 preceding siblings ...)
  2004-10-11 14:06 ` pinskia at gcc dot gnu dot org
@ 2004-10-11 14:12 ` pinskia at gcc dot gnu dot org
  2004-10-11 14:47 ` [Bug rtl-optimization/17931] [4.0 Regression] " kazu at cs dot umass dot edu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-11 14:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-11 14:12 -------
This is a regression from 2.95.3:
        movl 4(%esp),%eax
        testb $1,(%eax)
        jne .L3
        movb (%eax),%al
        shrb $1,%al
        andl $1,%eax
        ret
        .p2align 4,,7
.L3:
        movl $1,%eax
        ret
And 3.0.4:
foo:
        movl    4(%esp), %eax
        testb   $1, (%eax)
        je      .L2
        movl    $1, %eax
        ret
        .p2align 4,,7
.L2:
        movzbl  (%eax), %eax
        shrb    %al
        andl    $1, %eax
        ret
And 3.2.3,3.3.3, and 3.4.0:
foo:
        movl    4(%esp), %eax
        movl    $1, %edx
        movzbl  (%eax), %eax
        testb   $1, %al
        jne     .L1
        shrb    %al
        movl    %eax, %edx
        andl    $1, %edx
.L1:
        movl    %edx, %eax
        ret
        .size   foo, .-foo
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.4.0"

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |minor
      Known to fail|                            |4.0.0
      Known to work|                            |3.3.3 3.0.4 2.95.3 3.4.0
            Summary|andl and testb are not      |[4.0 Regresion] andl and
                   |combined                    |testb are not combined
   Target Milestone|---                         |4.0.0


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


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

* [Bug rtl-optimization/17931] [4.0 Regression] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
                   ` (3 preceding siblings ...)
  2004-10-11 14:12 ` [Bug rtl-optimization/17931] [4.0 Regresion] " pinskia at gcc dot gnu dot org
@ 2004-10-11 14:47 ` kazu at cs dot umass dot edu
  2004-10-11 15:32 ` kazu at cs dot umass dot edu
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-11 14:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-10-11 14:47 -------
The combiner does try to combine andl and testb,
but the suggested combined insn is rejected by combine_validate_cost.

The cost of "andl $1, %eax" is 4.
The cost of "testb %al, %al" is 4.
So the original total cost is 8.

The cost of the combined insn, shown below, is 12.

(set (reg:CCZ 17 flags)
    (compare:CCZ (zero_extract:SI (subreg:SI (reg:QI 63) 0)
            (const_int 1 [0x1])
            (const_int 0 [0x0]))
        (const_int 0 [0x0])))

We need to teach ix86_rtx_cost to treat
(compare (zero_extract X (const_1) ...)) the same as and.


-- 


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


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

* [Bug rtl-optimization/17931] [4.0 Regression] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
                   ` (4 preceding siblings ...)
  2004-10-11 14:47 ` [Bug rtl-optimization/17931] [4.0 Regression] " kazu at cs dot umass dot edu
@ 2004-10-11 15:32 ` kazu at cs dot umass dot edu
  2004-10-12 14:11 ` kazu at cs dot umass dot edu
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-11 15:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-10-11 15:32 -------
I'll be testing a patch shortly.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |kazu at cs dot umass dot edu
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug rtl-optimization/17931] [4.0 Regression] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
                   ` (5 preceding siblings ...)
  2004-10-11 15:32 ` kazu at cs dot umass dot edu
@ 2004-10-12 14:11 ` kazu at cs dot umass dot edu
  2004-10-12 17:22 ` cvs-commit at gcc dot gnu dot org
  2004-10-12 17:57 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-10-12 14:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-10-12 14:11 -------
A patch posted at:
http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00986.html


-- 


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


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

* [Bug rtl-optimization/17931] [4.0 Regression] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
                   ` (6 preceding siblings ...)
  2004-10-12 14:11 ` kazu at cs dot umass dot edu
@ 2004-10-12 17:22 ` cvs-commit at gcc dot gnu dot org
  2004-10-12 17:57 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-10-12 17:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-10-12 17:21 -------
Subject: Bug 17931

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2004-10-12 17:14:43

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c 

Log message:
	PR rtl-optimization/17931
	* config/i386/i386.c (ix86_rtx_costs): Handle COMPARE with
	ZERO_EXTRACT in it.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5846&r2=2.5847
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&r1=1.734&r2=1.735



-- 


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


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

* [Bug rtl-optimization/17931] [4.0 Regression] andl and testb are not combined
  2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
                   ` (7 preceding siblings ...)
  2004-10-12 17:22 ` cvs-commit at gcc dot gnu dot org
@ 2004-10-12 17:57 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-12 17:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-12 17:57 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2004-10-12 17:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-11 13:52 [Bug rtl-optimization/17931] New: andl and testb are not combined kazu at cs dot umass dot edu
2004-10-11 13:54 ` [Bug rtl-optimization/17931] " kazu at cs dot umass dot edu
2004-10-11 14:01 ` pinskia at gcc dot gnu dot org
2004-10-11 14:06 ` pinskia at gcc dot gnu dot org
2004-10-11 14:12 ` [Bug rtl-optimization/17931] [4.0 Regresion] " pinskia at gcc dot gnu dot org
2004-10-11 14:47 ` [Bug rtl-optimization/17931] [4.0 Regression] " kazu at cs dot umass dot edu
2004-10-11 15:32 ` kazu at cs dot umass dot edu
2004-10-12 14:11 ` kazu at cs dot umass dot edu
2004-10-12 17:22 ` cvs-commit at gcc dot gnu dot org
2004-10-12 17:57 ` 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).