I don't know what Nim do but AFAIK in D you're (voluntarily) limited in what you can do at compile time because in effect with Jai compiling a program is running it, so this can have security implications..
In theory a good optimizing compiler should see that some code doesn't depend on anything external and do it, but I'm not sure to what extent they do. GCC with higher optimization settings does do some pretty crazy stuff, so I would expect it to figure out something like in the example code pretty easily.
I don't know well enough how they compare to give any thorough analysis, though.