Switch codegen.

claptrap clap at trap.com
Sun Aug 13 18:57:42 UTC 2023


On Sunday, 13 August 2023 at 13:13:30 UTC, Johan wrote:
> I'm quite certain that if `x` is constant, the bounds check and 
> table lookup will be hoisted out of the loop, indeed leading to 
> just an indirect jump inside the loop.
> Of course, this requires running the optimizer (-Ox, x>0).

I've tried as many variations as I can figure and it always 
generates this...

```D
     cmp     r14d, 3
     ja      .LBB0_9
     movsxd  rax, dword ptr [r12 + 4*r15]
     add     rax, r12
     jmp     rax
```

https://d.godbolt.org/z/jzoevxoG4

That's with O2, with O3 I cant make head nor tail of the code it 
generates, it's some pretty insane optimization.

With my own code I use "asm int 3" to breakpoint in the function, 
so I can look at the disassembly even with O3 optimization, using 
visual studio, and it still generates those 5 instructions.




More information about the digitalmars-d-ldc mailing list