Jump to content

VilleK

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. When optimizations are turned off in Delphi IDE the code is worse: - Each assign to "sum" variable is a load to register from stack, modify register, store back to stack. Same for loop iteration variable "i". - Loop start is not on aligned address - Loop count upwards instead of downwards requiring a compare at the end instead of just jump if not zero. So the compiler do some optimizations but they are very very basic.
  2. I agree. It seems no LLVM optimizations passes are enabled, which corresponds with what others have reported about the mobile LLVM compilers. And this is very disappointing.
  3. Compiling this simple program: program test; {$OPTIMIZATION ON} {$STACKFRAMES OFF} procedure loop; var i,sum : integer; begin sum := 0; for i := 0 to 1000 do sum := sum + 1; end; begin loop; end. Generates the following code (Delphi Mac 64-bit compiler, release build): __project1_loop PROC push rbp mov rbp, rsp mov dword ptr [rbp-8H], 0 mov dword ptr [rbp-0CH], 1001 ALIGN 16 ?_001: inc dword ptr [rbp-8H] dec dword ptr [rbp-0CH] jnz ?_001 pop rbp ret __project1_loop ENDP Some point to notice: - The loop procedure has a stack frame even though we've turned them off - It does not try to use registers for local variables. Both "i" and "sum" are allocated on the stack. - Since the loop body has no side effects and the result is not used then the whole loop can be optimized away. This happens with the same code written in C and compiled with Clang compiler. Clang is interesting comparison because it also uses LLVM infrastructure so it gives an idea of what kind of optimizations that are possible. - If we were to change the loop so the result variable is used (by printing the content of "sum" variable) then Clang will recognize that the loop can be evaluated at compile time and replace it with the equivalent code of printing that constant. Again, Delphi does not do this. See result of Clang here.
×