[LLVMdev] A small pass to constant fold branch conditions in destination blocks
Duncan Sands
baldrick at free.fr
Tue Feb 8 02:03:20 PST 2011
Hi Owen,
> GVN already does this. See lines 1669-1689.
you are mistaken. If you try running GVN on the example you will see that it
doesn't do anything to it. The problem is that GVN only applies its logic when
it simplifies an expression due to value numbering. If value numbering gives
nothing (like for the returns in the example) then it doesn't do anything. I
first noticed this because instsimplify improvements mean that GVN's value
numbering catches less stuff (because it was caught earlier) and thus its
correlated expression logic doesn't kick in resulting in less simplifications,
i.e. improving instsimplify can cause regressions due to this GVN flaw. I
opened PR9004 for this.
Ciao, Duncan.
>
> --Owen
>
> On Feb 7, 2011, at 4:50 AM, Duncan Sands wrote:
>
>> Hi all, I wrote a little pass (attached) which does the following: if it sees a
>> conditional branch instruction then it replaces all occurrences of the condition
>> in the true block with "true" and in the false block with "false". Well, OK, it
>> is a bit more sophisticated (and a bit more careful!) than that but you get the
>> idea. It will turn this
>> define i1 @t1(i1 %c) {
>> br i1 %c, label %t, label %f
>> t:
>> ret i1 %c
>> f:
>> ret i1 %c
>> }
>> into this
>> define i1 @t1(i1 %c) {
>> br i1 %c, label %t, label %f
>> t:
>> ret i1 true
>> f:
>> ret i1 false
>> }
>> for example. Curiously enough LLVM doesn't seem to have a pass that does this.
>> I took a look at the effect on the testsuite by scheduling a run of this pass
>> just after each run of -correlated-propagation. In spite of being so simple
>> (not to say simplistic) it has an enormous positive impact on Ada code and a
>> substantial positive impact throughout the LLVM test-suite (I didn't check that
>> programs still work after running the pass, so it could be that it has such a
>> big effect because it is wrong!).
>>
>> So... should this kind of logic be incorporated into LLVM? Perhaps as part of
>> an existing pass like -correlated-propagation?
>>
>> It would be easy to make the pass a bit more powerful. For example if the
>> condition was "X == 0" then it could also replace X with 0 everywhere in the
>> true block.
>>
>> Ciao, Duncan.
>>
>> PS: This was inspired by PR9004.
>> <Prop.cpp>_______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
More information about the llvm-dev
mailing list