http://llvm.org/bugs/show_bug.cgi?id=6212

           Summary: Clang misses optimisation on if vs else if
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


int test1(int mainType, int subType)
{
        if(mainType == 7)
        {
                subType = 4;
        }

        else if(mainType == 9)
        {
                subType = 6;
        }

        else if(mainType == 11)
        {
                subType = 9;
        }
        return subType;
}

int test2(int mainType, int subType)
{
        if(mainType == 7)
        {
                subType = 4;
        }

        if(mainType == 9)
        {
                subType = 6;
        }

        if(mainType == 11)
        {
                subType = 9;
        }
        return subType;
}

Clang generates more efficient code in the second case than the first, because
the first is transformed into a switch which then gets expanded to longer code
by the code generator.


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to