An LLVM bug that affect both LDC and SDC. Worth pushing for

dennis luehring via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 18 21:45:08 PDT 2014


Am 18.06.2014 23:22, schrieb Iain Buclaw via Digitalmars-d:
> Likewise here.  But unless I'm missing something (I'm not sure what
> magic happens with @allocate, for instance), I'm not sure how you
> could expect the optimisation passes to squash closures together.
>
> Am I correct in that it's asking for:
> ------
> int *i = new int;
> *i = 42;
> return *i;
>
>
> To be folded into:
> ------
> return 42;

just to show what clang 3.5 svn and libc++ can currently optimize down

patches
clang: http://reviews.llvm.org/rL210137
libc++: http://reviews.llvm.org/rL210211

#example 1

#include <vector>
#include <numeric>
int main()
{
     const std::vector<int> a{1,2};
     const std::vector<int> b{4,5};
     const std::vector<int> ints
     {
       std::accumulate(a.begin(),a.end(),1),
       std::accumulate(b.begin(),b.end(),2),
     };
     return std::accumulate(ints.begin(),ints.end(),100);
}

asm result:

main:                                   # @main
    movl  $115, %eax
    retq

#example 2

#include <string>
int main()
{
    return std::string("hello").size();
}

asm result:

main:                                   # @main
    movl $5, %eax
    retq

an older clang/libc++, gcc 4.9.x, and VS2013 producing much much (much) 
more asm code in these situations


More information about the Digitalmars-d mailing list