This is the mail archive of the gcc@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: Switch optimization idea


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


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