GDC compiler settings on codechef

Thanks! How long does it usually take until the next iteration of language updates? The comment about the status of programming languages and compilers was last updated in 2017. I can see that in 2019 there was a report about Rust compiler not enabling optimizations, but nobody replied in the forum. Running the test program from that forum post shows that the Rust optimizations issue is resolved now.

I have implemented a configuration sanity checker for D language too, which can be run in the codechef IDE mode:

import std.stdio, std.range, std.algorithm;

// Optimizing compilers should do tail call optimization here, so
// 0xBADF00D magic constant won't be found in stack if optimizations
// are enabled. Is there a cleaner way to detect optimizations?
bool detect_opt() {
  int[100] filler;
  bool detect_tail_call_opt(int depth, int magic) {
    if (depth > 100) {
      int x; foreach (i ; 20 .. 80) if (*(&x + i) == magic) return false;
      return true;
    }
    return detect_tail_call_opt(depth + 1, magic);
  }
  return filler[0] || detect_tail_call_opt(0, 0xBADF00D);
}

// GDC11 was the first version to start supporting getTargetInfo traits
bool detect_gdc11() {
  version(GNU) { return __traits(compiles, __traits(getTargetInfo, "cppStd")); }
  else return false;
}

void main() {
  bool assert_on = false, optimizations_on = detect_opt();
  version(assert) { assert_on = true; }
  string[] warnings;
  version(GNU) {
    writeln("Detected compiler: GDC");
    if (!optimizations_on)
      warnings ~= "Performance warning: '-O3' option was not used!";
    if (assert_on)
      warnings ~= "Performance warning: '-frelease' option was not used!";
    if (detect_gdc11())
      warnings ~= "Note: GDC11 or newer may need '-flto' option, see https://gcc.gnu.org/PR102765";
  } else version(LDC) {
    writefln("Detected compiler: LDC (optimizing for %s)", __traits(targetCPU));
    if (!optimizations_on)
      warnings ~= "Performance warning: '-O' option was not used!";
    if (assert_on)
      warnings ~= "Performance warning: '-release' option was not used!";
    if (__traits(targetCPU) == "pentium4")
      warnings ~= "Performance warning: '-mcpu=native' option was not used!";
  } else version(DigitalMars) {
    writeln("Detected compiler: DMD");
    if (!optimizations_on)
      warnings ~= "Performance warning: '-O' option was not used!";
    if (assert_on)
      warnings ~= "Performance warning: '-release' option was not used!";
    warnings ~= "Performance warning: DMD generates much slower code than GDC or LDC!";
  } else {
    warnings ~= "Unknown compiler";
  }
  if (size_t.sizeof < 8)
    warnings ~= "Performance warning: not a 64-bit compiler!";
  if (warnings.empty)
    writeln("Everything seems to be properly configured.");
  else
    writeln(warnings.joiner("\n"));
}

Would it be possible to just quickly add “-O3 -frelease” options to the command line of your GDC 6.3 compiler?

There is no time limit multiplier for D and it’s treated as a high performance optimizing compiler with the same time limits as C++. Also looks like I’m the only remaining user of the D language on the codechef platform at the moment (based on checking submissions for a few recent contests). So the risk of making the users unhappy by breaking something is pretty low.