Fuzzing D code with LDC

- 17 mins read
A not-so-well-written article about the fuzzing capability recently added to LDC, using LLVM’s libFuzzer. Compiling code with -fsanitize=fuzzer adds control-flow instrumentation used to guide the fuzzing and links-in the libFuzzer library that drives the fuzz testing (same as Clang). -fsanitize=fuzzer is available from LDC 1.4.0, not on Windows. LDC 1.6.0 was used for the examples in this article. Fuzzing and libFuzzer Fuzz testing (“fuzzing”) is a technique to find bugs by testing a (part of a) program many times with randomly generated input.
LDC comes with improved support for Address Sanitizer since the 1.4.0 release. Address Sanitizer (ASan) is a runtime memory write/read checker that helps discover and locate memory access bugs. ASan is part of the official LDC release binaries; to use it you must build with -fsanitize=address. In this article, I’ll explain how to use ASan, what kind of bugs it can find, and what bugs it will be able to find in the (hopefully near) future.
A short article about Link Time Optimization (LTO) with LDC, with a simple example demonstrating how it can increase the performance of programs. Because LTO works at the LLVM IR level, it enables optimization across the C++/D language barrier! Important: LDC/LLVM’s LTO is not available on Windows. Link Time Optimization Link Time Optimization (LTO) refers to program optimization during linking. The linker pulls all object files together and combines them into one program.

Increasing the performance of D math code

- 8 mins read
An article about the new @fastmath and __traits(target*) features in LDC 1.1.0. The @fastmath attribute relaxes floating point math constraints and is used by Mir to beat OpenBLAS and Eigen. To avoid confusion: LLVM is doing the interesting work, LDC just adds a few pieces that allow LLVM to work its magic. I’m afraid it won’t be a nice read if you are unfamiliar with some of peculiarities of the CPU’s floating point math, x86 assembly, or SIMD.
To speed up total compile time, LDC 1.1.0 can create an object file cache (#1572). When cache lookup succeeds in a second compilation pass, optimization and machine codegen can be skipped, reducing the compile time significantly. Tested on a large codebase, the total build time is reduced from ~3m30 (empty cache) to ~2m30 (no changes, all cache hits). All that’s needed is passing -ir2obj-cache=/tmp/ldccache to LDC, and… read the end to find out about an important detail.

Profile-Guided Optimization with LDC

- 8 mins read
Three months ago, I measured a 7% performance gain of the compiler front-end D code using Profile-Guided Optimization (PGO) with LDC. Now, part of my PGO work was merged into LDC master on Jun 20, 2016! This means it will be available in the next LDC release (version 1.1.0, needs LLVM 3.7 or newer). You can play with it with the LDC 1.1.0-alpha1 release. Here I’ll discuss how to use it, saving the implementation details for another article.
Part 1 on profile-guided optimizations (PGO) in LDC. An article about optimization of virtual (class) function calls using profile data by transforming indirect calls to direct calls, with a description of how this is implemented in LDC using LLVM. Edit (15 Apr 2016): The D code of LDC performs 7% faster (on the testcase) when compiled with PGO. I added “function” to the title so my father no longer thinks this is about video phone calls.