[LLVMdev] Why shouldn't function entry blocks have predecessors?

John McCall rjmccall at apple.com
Thu Jul 8 06:24:46 PDT 2010


On Jul 8, 2010, at 12:25 AM, FĂ©lix Cloutier wrote:

> It's past 3 AM here, so maybe I really shouldn't be answering in this state of awakeness. However, what I understand from your example is that loops with counters must be entered from another block in order to use the phi instruction correctly, not that it should be invalid to branch to the entry block.
> 
> It seems to me that it makes sense to go back to the entry point if looping is not directed by a counter. Consider the following snippet of invalid IR:
> 
> define i32 @foo() nounwind {
> entry:
> 	%time = call i32 @time(i32* null) nounwind
> 	%cmp = icmp eq i32 %time, 1234567890
> 	br i1 %cmp, label %exit, label %entry
> exit:
> 	ret i32 0
> }
> 
> declare i32 @time(i32*) nounwind
> 
> Is the problem really inherent to the entry block, or is it rather inherent to the use of the phi instruction from the entry block?

It's inherent to the entry block.  A lot of things are special about the entry block;  allowing branches to it would make everything else more complicated.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100708/1032a498/attachment.html>


More information about the llvm-dev mailing list