dmd codegen improvements

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 18 14:57:39 PDT 2015


On Tue, Aug 18, 2015 at 02:25:34PM -0700, Walter Bright via Digitalmars-d wrote:
> On 8/18/2015 1:47 PM, deadalnix wrote:
> >Realistically, D does not have the man power required to reach the
> >same level of optimization, and have many higher impact task to spend
> >that manpower on.
> 
> dmd also does a sludge of patterns. I'm just looking for a few that
> would significantly impact the result.

>From the little that I've seen of dmd's output, it seems that it's
rather weak in the areas of inlining and loop unrolling / refactoring.

Inner loops especially would benefit from much more aggressive inlining,
which dmd seems to be unable to do once the loop body gets moderately
complex. Unrolling in dmd seems to be very minimal or absent.

In both cases, it seems that the optimizer gives up too quickly -- an
if-else function body will get inlined, but an if without an else
doesn't, etc..  This means the slightest bump in the road will cause the
inliner to throw up its hands and not inline, which in turn causes
missed opportunities for further refactoring / simplification in the
calling function. Especially in range-based code, this can make a big
difference.

There's also the more general optimizations, like eliminating redundant
loads, eliding useless allocation of stack space in functions that
return constant values, etc.. While DMD does do some of this, it's not
as thorough as GDC. While it may sound like only a small difference, if
they happen to run inside an inner loop, they can add up to quite a
significant difference.

DMD needs to be much more aggressive in eliminating useless / redundant
code blocks; a lot of this comes not from people writing unusually
redundant code, but from template expansions and inlined range-based
code, which sometimes produce a lot of redundant operations if
translated directly.  Aggressively reducing these generated code blocks
will often open up further optimization opportunities.


T

-- 
The computer is only a tool. Unfortunately, so is the user. -- Armaphine, K5


More information about the Digitalmars-d mailing list