This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Switch optimization idea
- From: Jeff Law <law at redhat dot com>
- To: Steve Ellcey <sellcey at imgtec dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 22 Mar 2013 13:00:21 -0600
- Subject: Re: Switch optimization idea
- References: <ecf809e5-7e15-478f-a835-e0aea67a11eb at BAMAIL02 dot ba dot imgtec dot org>
On 03/22/2013 11:17 AM, Steve Ellcey wrote:
I am looking at implementing a GCC optimization pass based on constant
propagation into a switch statement.
Given:
if (expr)
s = 1;
codeX; (code that allows definition of s to propogate through)
switch (s) {
1: code1; break;
2: code2; break;
default: code3; break;
}
I would like to replace this with:
if (expr)
s = 1;
codeX;
go directly to label 1 of switch statement
codeX
switch (s) {
1: code1; break;
2: code2; break;
default: code3; break;
}
Obviously this optimization would only make sense if 'codeX' were
reasonably small chunk of code.
As others have pointed out, this is jump threading.
The reason you're not seeing jump threading in the CoreMark test is the
switch is inside a loop and threading a backedge is severely constrained.
There's a BZ for this issue with a bit more state for this issue.
jeff