[LLVMdev] A small pass to constant fold branch conditions in destination blocks

Frits van Bommel fvbommel at gmail.com
Mon Feb 7 07:30:49 PST 2011


On Mon, Feb 7, 2011 at 2:57 PM, Duncan Sands <baldrick at free.fr> wrote:
> Yes that's exactly what it would do, and this happens a lot in practice.  The
> reason that it fires a lot in Ada code for example if that the code is full of
> compiler generated checks (eg: every array access is checked) and the checks
> often end up being repeated (eg: because you access the same array element
> twice).  Now all the later checks are eliminated if they are implied by the
> earlier checks.

Of course, that only happens if the compares have already been CSE'd.
And it wouldn't handle e.g. 'arr.length > 10' followed by 'arr.length
> 5'...
This really needs to be implemented in a more generic pass to handle
cases like that (PR 9004 mentions LVI).

Maybe correlated value propagation should also look at all
non-constant operands of all instructions to see if LVI knows they can
be replaced by constants?
In fact it looks like this + SimplifyInstruction() afterwards could
obsolete the special handling for select, load and store while making
the pass more powerful.




More information about the llvm-dev mailing list