This is the mail archive of the gcc-bugs@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]

[Bug optimization/14721] New: jump optimization involving a sibling call within a jump table


We could put a function address in a jump table.

void bar0 (void);
void bar1 (void);
void bar2 (void);
void bar3 (void);
void bar4 (void);

void
foo (int i)
{
  switch (i)
    {
    case 0: bar0 (); break;
    case 1: bar1 (); break;
    case 2: bar2 (); break;
    case 3: bar3 (); break;
    case 4: bar4 (); break;
    }
}

Here is what I get on i686-pc-linux-gnu.

foo:
	movl	4(%esp), %eax
	cmpl	$4, %eax
	ja	.L1
	jmp	*.L8(,%eax,4)
	.section	.rodata
	.align 4
	.align 4
.L8:
	.long	.L3
	.long	.L4
	.long	.L5
	.long	.L6
	.long	.L7
	.text
	.p2align 2,,3
.L1:
	ret
.L7:
	jmp	bar4
.L3:
	jmp	bar0
.L4:
	jmp	bar1
.L5:
	jmp	bar2
.L6:
	jmp	bar3

It would be nice if I can get something like:

foo:
	movl	4(%esp), %eax
	cmpl	$4, %eax
	ja	.L1
	jmp	*.L8(,%eax,4)
	.section	.rodata
	.align 4
	.align 4
.L8:
	.long	bar0
	.long	bar1
	.long	bar2
	.long	bar3
	.long	bar4
	.text
	.p2align 2,,3
.L1:
	ret

-- 
           Summary: jump optimization involving a sibling call within a jump
                    table
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          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
 GCC build triplet: pessimizes-code


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


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