NO

Author Topic: Compiler generates bad code for (signed) long long modulo operator  (Read 2493 times)

RichieL

  • Guest
The following tiny procedure: "long long test(long long i) { return i % 4;}"
generates bad code when optimization is set to None; interestingly, when
optimization is set to Maximize Speed the generated code is correct.

The code generated with optimization=None is shown in attachment
noOpt.jpg (captured from the Pelles debugger).  The "cqo" instruction
takes its source from rax, but the compiler loads the numerator into
rdx instead. The optimized code (in Opt.jpg) correctly loads the numerator
into rax. There are three other instructions in noOpt.jpg that also reference
rdx when they should be, in this case, using rax.

Compiler is v8.00.60 (64-bit).

      Richie

RichieL

  • Guest
Re: Compiler generates bad code for (signed) long long modulo operator
« Reply #1 on: February 15, 2018, 07:13:01 AM »
Forgot to mention: code generated for "long" modulo is correct, optimizations or no optimizations. Only "long long" has the problem.