How to defeat the optimizer in GDC
Iain Buclaw
ibuclaw at gdcproject.org
Mon May 20 08:21:19 UTC 2019
On Monday, 20 May 2019 at 08:11:19 UTC, Mike Franklin wrote:
> I'm trying to benchmark some code, but the optimizer is
> basically removing all of it, so I'm benchmarking nothing.
>
> I'd like to do something like what Chandler Carruth does here
> to defeat the optimizer:
> https://www.youtube.com/watch?v=nXaxk27zwlk&feature=youtu.be&t=2446
>
> Here presents the following inline asm function to tell the
> optimizer that `p` is being used (at least that's how I
> understand it):
> ```
> void escape(void* p)
> {
> asm volatile("" : : "g"(p) : memory);
> }
> ```
>
> I tried to do the same thing in D with this function:
> ```
> void use(void* p)
> {
> version(LDC)
> {
> import ldc.llvmasm;
> __asm("", "r,~{memory}", p);
> }
> version(GDC)
> {
> asm { "" : : "g"(p), "memory"; }
> }
> }
> ```
>
> The LDC version seems to work fine:
> https://d.godbolt.org/z/qbg54J
>
> But I can't get GDC to do the same:
> https://explore.dgnu.org/z/quCjhU
>
> Is this currently possible in GDC?
>
Looks like you've done a typo to me. Memory should be a clobber,
not an input operand.
--
Iain
More information about the D.gnu
mailing list