[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-sparse
Subject:    CSE _and_ if-conversion
From:       Linus Torvalds <torvalds () osdl ! org>
Date:       2004-11-24 18:59:44
Message-ID: Pine.LNX.4.58.0411241021520.20993 () ppc970 ! osdl ! org
[Download RAW message or body]


Damn, I'm good.

I'm now doing a limited form of if-conversion, in that I convert 
good-looking phi-nodes into select operations. I'm not a big believer in 
general if-conversion with predicated instructions, but on the other hand 
I definitely _do_ want to get the trivial cases where we can just rewrite 
an if into a "select()". 

Iow, I believe that these test-cases should all be branch-free:

	int fn1(int argc, int a, int b)
	{
		int i;
		if (argc)
			i = a;
		else
			i = b;
		return i;
	}

	int fn2(int argc)
	{
		if (!argc)
			return -1;
		return argc;
	}

	int fn3(int argc, int a, int b)
	{
		int retval = a;
		if (argc)
			retval = b;
		return retval;
	}

since they really all boil down to the same thing: a select on a pseudo, 
with no actual real "code" in any of the cases, ie the linearization 
results in empty blocks that don't have anything but a phi-source note in 
them.

And dammit if sparse doesn't do that right now. Of course, I quite
possibly have bugs in it (I wouldn't be surprised if I can get the sense
of the "select" wrong at times), and right now it doesn't merge all the
basic blocks completely, because my bb packer still gets confused too
easily.

But the above three test-cases now linearizs to the appended
linearization. I've manually removed empty blocks, nop's and instructions
marked unused, and added notes on why something didn't merge, but I have
not actually changed anything else in any way.

Cool, no?

		Linus

----

  ep 0xf7fe200c: fn1	
	ENTRY:
	bb: 0xf7f9e00c
	   test.c:1:5
	  **to 0xf7f9e06c (test.c:8:2)**
	  **to 0xf7f9e06c (test.c:8:2)**
		setcc %arg1
		%r6 <- select  %arg2, %arg3
		br	.L0xf7f9e06c

	/* Not merged: "two parents" and "stale phi source" */
	bb: 0xf7f9e06c
	   test.c:8:2
	  **from 0xf7f9e00c (test.c:1:5)**
	  **from 0xf7f9e00c (test.c:1:5)**
	  **phi source (%r6,.L0xf7f9e06c)**
		ret %r6
	
	
  ep 0xf7fe2028: fn2	
	ENTRY:
	bb: 0xf7f9e0ac
	   test.c:11:5
	  **to 0xf7f9e10c (test.c:11:5)**
	  **to 0xf7f9e10c (test.c:11:5)**
		setcc %arg1
		%r8 <- select  %arg1, $0xffffffff
		br	.L0xf7f9e10c
	
	/* Not merged: "two parents" */
	bb: 0xf7f9e10c
	   test.c:11:5
	  **from 0xf7f9e0ac (test.c:11:5)**
	  **from 0xf7f9e0ac (test.c:11:5)**
		ret %r8
	
	
  ep 0xf7fe2044: fn3	
	ENTRY:
	bb: 0xf7f9e12c
	   test.c:18:5
	  **to 0xf7f9e16c (test.c:23:2)**
	  **to 0xf7f9e16c (test.c:23:2)**
		setcc %arg1
		%r15 <- select  %arg3, %arg2
		br	.L0xf7f9e16c
	
	/* Not merged: "two parents" and "stale phi source" */
	bb: 0xf7f9e16c
	   test.c:23:2
	  **from 0xf7f9e12c (test.c:18:5)**
	  **from 0xf7f9e12c (test.c:18:5)**
	  **phi source (%r15,.L0xf7f9e16c)**
		ret %r15
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic