This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Crossjumping of tablejumps


> > this patch adds crossjumping of identical tablejumps. When there are
> > two identical jump tables, it replaces the references to one table by
> > references to another and then crossjumping deletes common instructions
> > as usual resulting in deleting of one jump table. The code size is thus
> > smaller.
> 
> Not ok.
> 
> You've got to do much more work to verify that this is legal on any target
> for which (1) the jump table is in the text section and (2) there are
> pc-relative references from the tablejump insn to the table.

Well, I'm replacing references to one table by references to another
so that I could merge the tables and to redirect the references to the
common table. One tablejump instruction and the offset calculation is
removed when crossjumping, so although the code is temporary wrong, it
should be fixed by removing one tablejump instruction and jumping to the
common code (tablejump insn + offset computing + maybe some more).
So I think the result is correct.

> As a first cut, I might allow this if !JUMP_TABLES_IN_TEXT_SECTION.
If my previous paragraph is wrong I'll add this test.

> What have you tried this on other than x86?

I have tried only i386 and x86-64. I have grepped config directory and
I do not think I can access any machine with JUMP_TABLES_IN_TEXT_SECTION != 0.
Now I have tried crosscompiling for m68k-*-elf* which does have jump
table is in the text section and  there are pc-relative references from
the tablejump insn to the table.
The code is seems to me to be correct:

Without patch:                                  With patch:

        .file        "f.c"                              .file        "f.c"
        .text                                           .text
        .align        2                                 .align        2
        .globl        main                              .globl        main
        .type        main, @function                    .type        main, @function
main:                                           main:
        link.w %a6,#0                                   link.w %a6,#0
        move.l f,%a0                                    move.l f,%a0
        move.l (%a0),%d0                                move.l (%a0),%d0
        jbeq .L3                                        jbeq .L11
        moveq.l #1,%d1                                  moveq.l #1,%d1
        cmp.l %d0,%d1                                   cmp.l %d0,%d1
        jbeq .L11                                       jbne .L2
        jbra .L2                                        .align        2
        .align        2                         .L11:
.L3:                                                    move.l g,%a0
        move.l g,%a0                                    moveq.l #4,%d0
        moveq.l #4,%d0                                  cmp.l (%a0),%d0
        cmp.l (%a0),%d0                                 jbcs .L2
        jbcs .L2                                        move.l (%a0),%d0
        move.l (%a0),%d0                                .set .LI18,.+2
        .set .LI10,.+2                                  move.w .L18-.LI18.b(%pc,%d0.l*2),%d0
        move.w .L10-.LI10.b(%pc,%d0.l*2),%d0            jmp %pc@(2,%d0:w)
        jmp %pc@(2,%d0:w)                               .align        2
        .align        2                                 .swbeg        &5
        .swbeg        &5                        .L18:
.L10:                                                   .word .L13-.L18
        .word .L13-.L10                                 .word .L15-.L18
        .word .L15-.L10                                 .word .L15-.L18
        .word .L15-.L10                                 .word .L17-.L18
        .word .L17-.L10                                 .word .L17-.L18
        .word .L17-.L10                                 .align        2
        .align        2                         .L13:
.L11:                                                   move.l g,%a0
        move.l g,%a0                                    moveq.l #1,%d1
        moveq.l #4,%d0                                  jbra .L19
        cmp.l (%a0),%d0                                 .align        2
        jbcs .L2                                .L15:
        move.l (%a0),%d0                                move.l g,%a0
        .set .LI18,.+2                                  moveq.l #1,%d0
        move.w .L18-.LI18.b(%pc,%d0.l*2),%d0            move.l %d0,(%a0)
        jmp %pc@(2,%d0:w)                               jbra .L2
        .align        2                                 .align        2
        .swbeg        &5                        .L17:
.L18:                                                   move.l g,%a0
        .word .L13-.L18                                 moveq.l #2,%d1
        .word .L15-.L18                         .L19:
        .word .L15-.L18                                 move.l %d1,(%a0)
        .word .L17-.L18                                 .align        2
        .word .L17-.L18                         .L2:
        .align        2                                 clr.l %d0
.L13:                                                   unlk %a6
        move.l g,%a0                                    rts
        moveq.l #1,%d1                                  .size        main, .-main
        jbra .L19                                       .comm        g,4,2
        .align        2                                 .comm        f,4,2
.L15:
        move.l g,%a0
        moveq.l #1,%d0
        move.l %d0,(%a0)
        jbra .L2
        .align        2
.L17:
        move.l g,%a0
        moveq.l #2,%d1
.L19:
        move.l %d1,(%a0)
        .align        2
.L2:
        clr.l %d0
        unlk %a6
        rts
        .size        main, .-main
        .comm        g,4,2
        .comm        f,4,2

Josef


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]