Skip to content
GitLab
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • FPC
  • FPC FPC
  • FPC SourceFPC Source
  • Issues
  • #40398

Compiler should optimize 'for' loops in the near zero range

by 'lagprogramming'.

Must be marked as related to #40370 (Compiler should optimize some comparisons with -1).

  • for signedvariable:=value to -1 do produces code where the value of a register is compared with -1.
  • for (un)signedvariable:=value downto 1 do produces code where the value of a register is compared with 1.

In both cases the compiler might produce code that compares with 0, not with 1 or -1 because, depending on the target, it may optimize the comparisons. For example:

  • instead of cmp a register value with 1 and then jumping on the condition >=1, it's better to test the register and then jump on the condition >0.
  • instead of cmp a register value with -1 and then jumping on the condition <=-1, it's better to test the register and then jump on the condition <0.
Edited Aug 15, 2023 by Alexey Torgashin
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking