[LLVMdev] complex branching generation

Villmow, Micah Micah.Villmow at amd.com
Wed Oct 1 13:19:52 PDT 2008

LLVM seems to be generating way too complex of branching based on the
short-circuit optimization. The code in question is as follows:

define void @ test_fc_while_and(float %x, float %y, float addrspace(11)*
%result) nounwind  {


        %tobool3 = fcmp une float %x, 0.000000e+000             ; <i1>

        %tobool24 = fcmp une float %y, 0.000000e+000            ; <i1>

        %or.cond5 = and i1 %tobool3, %tobool24          ; <i1> [#uses=1]

        br i1 %or.cond5, label %bb.nph, label %whileexit


bb.nph:         ; preds = %entry

        br i1 %tobool24, label %whilebody.us, label %whilebody


whilebody.us:           ; preds = %whilebody.us, %bb.nph

...code here...

        br i1 %phitmp, label %whilebody.us, label %whileexit


whilebody:              ; preds = %bb.nph

...code here...

        br label %whileexit


whileexit:              ; preds = %whilebody, %whilebody.us, %entry

        %z.0.lcssa = phi float [ 0.000000e+000, %entry ], [ %add,
%whilebody ], [ %add.us, %whilebody.us ]              ; <float>

        store float %z.0.lcssa, float addrspace(11)* %result

        ret void


based on original code of:

void test_fc_while_and(float x, float y, float* result)


        float z = (float)0;

        while (x && y) {

        z += (x * y);



        *result = z;



Now the problem issue is with the bolded code. The two comparisons and
the and instruction that are mapped to the bolded while statement. What
I am trying to figure out why the bb.nph branch is even required and how
do I disable it from being generated? The first branch instruction
handles correctly the condition that I wanted, so there should be no
reason that bb.nph is generated. The same for whilebody, as it shouldn't
be there.


Any ideas?



Micah Villmow

Systems Engineer

Advanced Technology & Performance

Advanced Micro Devices Inc.

4555 Great America Pkwy,

Santa Clara, CA. 95054

P: 408-572-6219

F: 408-572-6596


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20081001/83ae99fa/attachment.html>

More information about the llvm-dev mailing list