public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/18076] New: Missed jump threading optimization
@ 2004-10-20 12:04 steven at gcc dot gnu dot org
  2004-10-20 14:35 ` [Bug tree-optimization/18076] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-10-20 12:04 UTC (permalink / raw)
  To: gcc-bugs

On AMD64 the following piece of code still triggers one jump 
threading opportunity in the RTL threader that we miss it in 
the tree threader on the tree-cleanup-branch: 
 
===================================================== 
extern int x; 
extern int y; 
 
void 
foo (void) 
{ 
  if ((x & 0x00000001) || (x & 0x00004000)) 
    y = 0; 
  if ((x & 0x00000001) || (x & 0x00004000)) 
    y = 1; 
  if ((x & 0x00000001) || (x & 0x00004000)) 
    y = 2; 
  if ((x & 0x00000001) || (x & 0x00004000)) 
    y = 3; 
  if ((x & 0x00000001) || (x & 0x00004000)) 
    y = 4; 
} 
===================================================== 
 
This test case was reduced from insn-opinit.c where we're still 
threading 405 jumps, most of them of the kind shown in the test 
case, with the RTL threader. 
 
We do catch this on mainline. 
 
The assembly for the tree-cleanup-branch is worse than mainline: 
 
MAINLINE: -O2                           TCB: -O2 
        .file   "t.c"                           .file   "t.c" 
        .text                                   .text 
        .p2align 4,,15                          .p2align 4,,15 
.globl foo                                      .globl foo 
        .type   foo, @function                  .type   foo, @function 
foo:                                    foo: 
.LFB2:                                  .LFB2: 
        movl    x(%rip), %eax                   movl    x(%rip), %eax 
        movl    %eax, %edx                      movl    %eax, %edx 
        andl    $1, %edx                        andl    $1, %edx 
        jne     .L2                             jne     .L2 
        testb   $64, %ah                        testb   $64, %ah 
        je      .L19                  |         je      .L4 
.L2:                                    .L2: 
        testb   %dl, %dl                        testb   %dl, %dl 
        movl    $0, y(%rip)                     movl    $0, y(%rip) 
        je      .L23                  |         jne     .L5 
                                      >         testb   $64, %ah 
                                      >         je      .L4 
                                      > .L5: 
        testb   %dl, %dl                        testb   %dl, %dl 
        movl    $1, y(%rip)                     movl    $1, y(%rip) 
        je      .L24                  |         je      .L4 
.L10:                                 < 
        testb   %dl, %dl                        testb   %dl, %dl 
        movl    $2, y(%rip)                     movl    $2, y(%rip) 
        je      .L25                  |         je      .L16 
.L14:                                 | .L9: 
        testb   %dl, %dl                        testb   %dl, %dl 
        movl    $3, y(%rip)                     movl    $3, y(%rip) 
        je      .L26                  |         je      .L17 
.L17:                                 | .L12: 
        movl    $4, y(%rip)                     movl    $4, y(%rip) 
.L19:                                 | .L14: 
        rep ; ret                               rep ; ret 
        .p2align 4,,7                           .p2align 4,,7 
.L23:                                 | .L4: 
        testb   $64, %ah                        testb   $64, %ah 
        je      .L19                  |         je      .L14 
        testb   %dl, %dl              < 
        movl    $1, y(%rip)           < 
        jne     .L10                  < 
.L24:                                 < 
        testb   $64, %ah              < 
        je      .L19                  < 
        testb   %dl, %dl                        testb   %dl, %dl 
        movl    $2, y(%rip)                     movl    $2, y(%rip) 
        jne     .L14                  |         jne     .L9 
.L25:                                 |         jmp     .L16 
                                      >         .p2align 4,,7 
                                      > .L17: 
        testb   $64, %ah                        testb   $64, %ah 
        je      .L19                  |         .p2align 4,,2 
                                      >         je      .L14 
                                      >         movl    $4, y(%rip) 
                                      >         .p2align 4,,4 
                                      >         jmp     .L14 
                                      >         .p2align 4,,7 
                                      > .L16: 
                                      >         testb   $64, %ah 
                                      >         .p2align 4,,2 
                                      >         je      .L14 
        testb   %dl, %dl                        testb   %dl, %dl 
        movl    $3, y(%rip)                     movl    $3, y(%rip) 
        jne     .L17                  |         jne     .L12 
.L26:                                 < 
        testb   $64, %ah              < 
        jne     .L17                  < 
        .p2align 4,,2                           .p2align 4,,2 
        ret                           |         jmp     .L17 
.LFE2:                                  .LFE2: 
        .size   foo, .-foo                      .size   foo, .-foo 
 
This could come from no longer iterating DOM, I guess??

-- 
           Summary: Missed jump threading optimization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: steven at gcc dot gnu dot org
                CC: dnovillo at redhat dot com,gcc-bugs at gcc dot gnu dot
                    org


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
@ 2004-10-20 14:35 ` pinskia at gcc dot gnu dot org
  2004-10-21 13:11 ` dnovillo at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-20 14:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-20 14:35 -------
If I make the x variable a paramater and y a variable (return y so that y is still used) then it works on the 
tree level so this is an aliasing causing missed optimization.
Aka this works:
int
foo (int x)
{
 int y =-1;
 if ((x & 0x00000001) || (x & 0x00004000))
    y = 0;
  if ((x & 0x00000001) || (x & 0x00004000))
    y = 1;
  if ((x & 0x00000001) || (x & 0x00004000))
    y = 2;
  if ((x & 0x00000001) || (x & 0x00004000))
    y = 3;
  if ((x & 0x00000001) || (x & 0x00004000))
    y = 4;
  return y;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |alias
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-20 14:35:09
               date|                            |


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
  2004-10-20 14:35 ` [Bug tree-optimization/18076] " pinskia at gcc dot gnu dot org
@ 2004-10-21 13:11 ` dnovillo at gcc dot gnu dot org
  2005-02-15  1:01 ` law at redhat dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-10-21 13:11 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|dnovillo at redhat dot com  |
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
  2004-10-20 14:35 ` [Bug tree-optimization/18076] " pinskia at gcc dot gnu dot org
  2004-10-21 13:11 ` dnovillo at gcc dot gnu dot org
@ 2005-02-15  1:01 ` law at redhat dot com
  2005-04-23  1:01 ` law at redhat dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2005-02-15  1:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From law at redhat dot com  2005-02-14 20:43 -------
I'll note the updated jump threading selection code will catch all these
threading opportunities.  I get something like this:


foo:
        pushl   %ebp
        movl    %esp, %ebp
        movl    x, %eax
        testb   $1, %al
        jne     .L2
        testb   $64, %ah
        je      .L7
.L2:
        movl    $3, y
        movl    $4, y
.L7:
        leave
        ret


I'll note we still have dead stores.   :(  Missed by both the tree-ssa
optimizers because we don't handle V_MUST_DEF and the RTL optimizers for reasons
unknown.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at redhat dot com


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-02-15  1:01 ` law at redhat dot com
@ 2005-04-23  1:01 ` law at redhat dot com
  2005-04-23 16:54 ` steven at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2005-04-23  1:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From law at redhat dot com  2005-04-23 01:01 -------
The threading part of this has been fixed  Now we just need to fix DSE to
finish cleaning things up.

-- 


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-04-23  1:01 ` law at redhat dot com
@ 2005-04-23 16:54 ` steven at gcc dot gnu dot org
  2005-04-25  5:02 ` law at redhat dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-04-23 16:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-04-23 16:54 -------
Nice.  And indeed surprising that the RTL DSE doesn't catch that trivially 
dead store.  Should I open a separate bug report for that? 
 

-- 


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-04-23 16:54 ` steven at gcc dot gnu dot org
@ 2005-04-25  5:02 ` law at redhat dot com
  2005-05-08 18:05 ` pinskia at gcc dot gnu dot org
  2005-06-05  7:46 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2005-04-25  5:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From law at redhat dot com  2005-04-25 05:02 -------
Subject: Re:  Missed jump threading
	optimization

On Sat, 2005-04-23 at 16:54 +0000, steven at gcc dot gnu dot org wrote:
> ------- Additional Comments From steven at gcc dot gnu dot org  2005-04-23 16:54 -------
> Nice.  And indeed surprising that the RTL DSE doesn't catch that trivially 
> dead store.  Should I open a separate bug report for that? 
Your call.  Or we could just link this bug into the existing DSE bug.

I think we'd be better off improving the tree DSE rather than the RTL
stuff.  This one is something we really should be catching before
we hand the code off to the RTL expanders.

jeff



-- 


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2005-04-25  5:02 ` law at redhat dot com
@ 2005-05-08 18:05 ` pinskia at gcc dot gnu dot org
  2005-06-05  7:46 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-08 18:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-08 18:04 -------
Fixed both the DSE and the threading issue.

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


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


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

* [Bug tree-optimization/18076] Missed jump threading optimization
  2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2005-05-08 18:05 ` pinskia at gcc dot gnu dot org
@ 2005-06-05  7:46 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-05  7:46 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.1.0


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


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

end of thread, other threads:[~2005-06-05  7:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 12:04 [Bug tree-optimization/18076] New: Missed jump threading optimization steven at gcc dot gnu dot org
2004-10-20 14:35 ` [Bug tree-optimization/18076] " pinskia at gcc dot gnu dot org
2004-10-21 13:11 ` dnovillo at gcc dot gnu dot org
2005-02-15  1:01 ` law at redhat dot com
2005-04-23  1:01 ` law at redhat dot com
2005-04-23 16:54 ` steven at gcc dot gnu dot org
2005-04-25  5:02 ` law at redhat dot com
2005-05-08 18:05 ` pinskia at gcc dot gnu dot org
2005-06-05  7:46 ` 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).