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

Duncan Sands baldrick at free.fr
Mon Feb 7 12:46:30 PST 2011


Hi Frits,

>> Here is a new and improved version that also does the following: if the
>> condition for a conditional branch has the form "A&&  B" then A, B and the
>> condition are all replaced with "true" in the true destination (similarly
>> for || conditions in the false destination).  Also, if the condition has
>> the form "X == Y" then X is replaced by Y everywhere in the true destination
>> (likewise if it is "X != Y" then X is replaced by Y everywhere in the false
>> destination).  Completely untested for correctness!
>
> I also had a try at this, integrating it with the existing correlated
> value propagation pass. See
> <http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20110207/116167.html>.

I will reply properly tomorrow, but for now let me just remark that querying LVI
for everything is probably very slow.  In fact I'm pretty sure that the reason
it only calculates things lazily is that calculating for everything would take
too much compile time.  And doubtless this is the reason why the correlated
value propagation pass only analyses a very limited set of instructions.

The big advantage of my technique is that it is fast.  The disadvantage is that
it is rather limited in what it can do.  Maybe some kind of combination would be
good: add the logic from my pass to correlated value propagation to quickly
forward propagate equality information from branch conditions, and reserve LVI
for analysing a small amount of important instructions.

Ciao, Duncan.



More information about the llvm-dev mailing list