Taming the optimizer

David Nadlinger code at klickverbot.at
Fri Jun 15 13:24:05 UTC 2018


Hi Mike,

On 14 Jun 2018, at 4:39, Mike Franklin via digitalmars-d-ldc wrote:
> What's the equivalent of...
>
> static void escape(void *p) {
>   asm volatile("" : : "g"(p) : "memory");
> }
>
> ... in LDC inline assembly?

As you probably found out already, the LLVM flavour inline assembly is 
somewhat sparsely documented. However, Clang supports GCC-style inline 
assembly, so if you have a piece of (GC)C code that does what you want, 
you can use its LLVM IR output as a guide.

For example, this is the relevant code generated for `escape`, obtained 
using `clang -emit-llvm -S` (on Apple clang-900.0.39.2):

   call void asm sideeffect "", 
"imr,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %0)

As the clobber string is generated programmatically, it might not always 
be as concise as possible, though, and sometimes there might be more 
than one supported syntax for the same concept (like `g` and `imr`).

If you wanted to come up with a well-researched proposal for druntime 
intrinsics to do these things (e.g. how would escape/use interact with 
CSE on strongly pure functions), this would be a very valuable 
contribution to the state of benchmarking in D.

  — David


More information about the digitalmars-d-ldc mailing list