public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/45223]  New: RTL PRE GCSE pass hoists trapping insn out of loop
@ 2010-08-07  8:24 ubizjak at gmail dot com
  2010-08-07  8:34 ` [Bug rtl-optimization/45223] " ubizjak at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-08-07  8:24 UTC (permalink / raw)
  To: gcc-bugs

This is a follow-up from PR38819 which partially fixes this problem. The
problem remains in RTL optimization passes, and can be triggered on targets
that implement modulo instruction in the hardware (i.e. moxie-elf).

The testcase from PR38819 compiles with -O2 to:

main:
        push   $sp, $r6
        push   $sp, $r7
        push   $sp, $r8
        push   $sp, $r9
        push   $sp, $r10
        push   $sp, $r11
        dec    $sp, 24
        lda.l  $r7, a
        lda.l  $r0, b
        xor    $r6, $r6
        ldi.l  $r11, foo
>	mod.l  $r7, $r0
        ldi.l  $r10, 8
        ldi.l  $r8, 99
        jmpa   .L4
.L3:
        ...

Since b is initialized to zero, mod.l instruction traps.


-- 
           Summary: RTL PRE GCSE pass hoists trapping insn out of loop
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ubizjak at gmail dot com
GCC target triplet: moxie-elf


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
@ 2010-08-07  8:34 ` ubizjak at gmail dot com
  2010-08-07  8:40 ` ubizjak at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-08-07  8:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ubizjak at gmail dot com  2010-08-07 08:33 -------
Following patch fixes this problem:

Index: gcse.c
===================================================================
--- gcse.c      (revision 162975)
+++ gcse.c      (working copy)
@@ -1693,7 +1693,7 @@ compute_hash_table_work (struct hash_tab

       /* The next pass builds the hash table.  */
       FOR_BB_INSNS (current_bb, insn)
-       if (INSN_P (insn))
+       if (INSN_P (insn) && !may_trap_p (PATTERN (insn)))
          hash_scan_insn (insn, table);
     }


main:
        push   $sp, $r6
        push   $sp, $r7
        push   $sp, $r8
        push   $sp, $r9
        push   $sp, $r10
        push   $sp, $r11
        dec    $sp, 28
        lda.l  $r0, a
        sto.l  -28($fp), $r0
        lda.l  $r11, b
        xor    $r6, $r6
        ldi.l  $r10, foo
        ldi.l  $r8, 8
        ldi.l  $r7, 99
        jmpa   .L4
.L3:
        lda.l  $r1, r
        ldo.l  $r0, -28($fp)
        mod.l  $r0, $r11
        add.l  $r0, $r1
        add.l  $r0, $r6
        sta.l  r, $r0
        inc    $r6, 1
        cmp    $r6, $r7
        bgt   .L7
.L4:
        jsr    $r10
        lda.l  $r0, x
        cmp    $r0, $r8
        bne   .L3
        inc    $r6, 1
        lda.l  $r1, r
        ldo.l  $r0, -28($fp)
>	mod.l  $r0, $r11
        add.l  $r0, $r1
        add.l  $r0, $r6
        sta.l  r, $r0
        inc    $r6, 1
        cmp    $r6, $r7
        ble   .L4
.L7:
        jsra   abort

In a general case, I guess that if it can be proved that denominator can't be
zero we can still hoist mod.l out of the loop.


-- 


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
  2010-08-07  8:34 ` [Bug rtl-optimization/45223] " ubizjak at gmail dot com
@ 2010-08-07  8:40 ` ubizjak at gmail dot com
  2010-08-07 10:58 ` steven at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-08-07  8:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ubizjak at gmail dot com  2010-08-07 08:40 -------
Ugh, with a bit changed testcase:

--cut here--
extern void exit (int);
extern void abort (void);

volatile float a = 1;
volatile float b = 0;
volatile int x = 2;
volatile signed int r = 8;

void __attribute__((noinline))
foo (void)
{
  exit (0);
}

int
main (void)
{
  float si1 = a;
  float si2 = b;
  int i;

  for (i = 0; i < 100; ++i) {
      foo ();
      if (x == 8)
        i++;
      r += i + (int) (si1 / si2);
  }
  abort ();
}
--cut here--

-O2 on x86_64-pc-linux-gnu:

main:
        pushq   %rbx
        xorl    %ebx, %ebx
        subq    $16, %rsp
        movss   a(%rip), %xmm0
        movss   %xmm0, 12(%rsp)
        movss   b(%rip), %xmm0
        movss   12(%rsp), %xmm1
>	divss	%xmm0, %xmm1
        movss   %xmm1, 12(%rsp)
.L4:
        call    foo
        ...

I hope that Ariane-5 is safe [1] ;)

[1] http://en.wikipedia.org/wiki/Ariane_5_Flight_501


-- 


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
  2010-08-07  8:34 ` [Bug rtl-optimization/45223] " ubizjak at gmail dot com
  2010-08-07  8:40 ` ubizjak at gmail dot com
@ 2010-08-07 10:58 ` steven at gcc dot gnu dot org
  2010-08-07 11:26 ` ubizjak at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: steven at gcc dot gnu dot org @ 2010-08-07 10:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from steven at gcc dot gnu dot org  2010-08-07 10:57 -------
Patch of comment #1 loops obviously OK to me. We shouldn't want to move
trapping insns in any case that I can think of.


-- 

steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-08-07 10:57:54
               date|                            |


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
                   ` (2 preceding siblings ...)
  2010-08-07 10:58 ` steven at gcc dot gnu dot org
@ 2010-08-07 11:26 ` ubizjak at gmail dot com
  2010-08-07 15:27 ` ubizjak at gmail dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-08-07 11:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ubizjak at gmail dot com  2010-08-07 11:26 -------
(In reply to comment #3)
> Patch of comment #1 loops obviously OK to me. We shouldn't want to move
> trapping insns in any case that I can think of.

OK, will post patch to gcc-patches after regression test.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |ubizjak at gmail dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2010-08-07 10:57:54         |2010-08-07 11:26:29
               date|                            |


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
                   ` (3 preceding siblings ...)
  2010-08-07 11:26 ` ubizjak at gmail dot com
@ 2010-08-07 15:27 ` ubizjak at gmail dot com
  2010-08-12 14:46 ` ubizjak at gmail dot com
  2010-09-04 10:03 ` ubizjak at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-08-07 15:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ubizjak at gmail dot com  2010-08-07 15:27 -------
Patch at [1].

[1] http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00553.html


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2010-
                   |                            |08/msg00553.html


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
                   ` (4 preceding siblings ...)
  2010-08-07 15:27 ` ubizjak at gmail dot com
@ 2010-08-12 14:46 ` ubizjak at gmail dot com
  2010-09-04 10:03 ` ubizjak at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-08-12 14:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from ubizjak at gmail dot com  2010-08-12 14:46 -------
Ouch, "Here are the ration of before and after on Intel Core i7. Gzip slowed
down by 10 to 20%." [1]

Richi says: "The fix is to teach LIM to do conditional invariant motion."

Probably also related to PR42108 catch-all PR.

[1] http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00771.html
[2] http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00884.html


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |42108


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


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

* [Bug rtl-optimization/45223] RTL PRE GCSE pass hoists trapping insn out of loop
  2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
                   ` (5 preceding siblings ...)
  2010-08-12 14:46 ` ubizjak at gmail dot com
@ 2010-09-04 10:03 ` ubizjak at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ubizjak at gmail dot com @ 2010-09-04 10:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from ubizjak at gmail dot com  2010-09-04 10:03 -------
Unassigning...


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|ubizjak at gmail dot com    |unassigned at gcc dot gnu
                   |                            |dot org
             Status|ASSIGNED                    |NEW


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


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

end of thread, other threads:[~2010-09-04 10:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-07  8:24 [Bug rtl-optimization/45223] New: RTL PRE GCSE pass hoists trapping insn out of loop ubizjak at gmail dot com
2010-08-07  8:34 ` [Bug rtl-optimization/45223] " ubizjak at gmail dot com
2010-08-07  8:40 ` ubizjak at gmail dot com
2010-08-07 10:58 ` steven at gcc dot gnu dot org
2010-08-07 11:26 ` ubizjak at gmail dot com
2010-08-07 15:27 ` ubizjak at gmail dot com
2010-08-12 14:46 ` ubizjak at gmail dot com
2010-09-04 10:03 ` ubizjak at gmail dot com

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