[llvm-commits] patch: preserve branch to unreachable until codegenprep time

Dan Gohman gohman at apple.com
Mon Oct 19 09:30:51 PDT 2009



On Oct 18, 2009, at 10:27 AM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Dan Gohman wrote:
>> On Oct 18, 2009, at 12:16 AM, Nick Lewycky <nicholas at mxc.ca> wrote:
>>> This patch moves the code that optimizes "branch to unreachable"  
>>> from SimplifyCFG to CodeGenPrep. Most of this patch is just  
>>> updating the unit tests that use unreachable everywhere. I've done  
>>> my best to preserve the intent of the tests.
>> I haven't read the patch, but I'm concerned about this interfering  
>> with other optimizations.  Deleting the condition can expose  
>> further dce and related optimizations.
>
> Yes, having extra instructions could interfere with optimizations.  
> Simple DCE isn't the problem though; when CodeGenPrep eliminates the  
> unreachables, it also DCEs the chain of computations.
>
> One case that could cause trouble is if an instruction had two uses,  
> one which fed into the "dead" branch and one which didn't, and  
> instcombine couldn't fold the instruction away only because it had  
> more than one use.

Indeed. Instcombine relies heavily on hasOneUse.

>
>  Also if the branch is a loop exit, deleting it
>> makes it easier to compute a trip count.
>
> They're easy to detect, just look for a BB whose first instruction  
> is "unreachable". I'll try making SCEV filter such blocks out of its  
> ExitingBlocks list.

LoopInfo would also need special-case code.

Dan



More information about the llvm-commits mailing list