Recent

Author Topic: Procedure optimization problem with local variable  (Read 4605 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Procedure optimization problem with local variable
« Reply #15 on: June 28, 2020, 04:34:44 pm »
Would you please report this as a bug with a selfcontained example?
In my opinion, this is not a bug. You can't force the compiler to optimize everywhere and always, something must remain for the developer.

You should leave that to e.g. Florian to decide. After all using inline the compiler might discover better optimization opportunities, but if something like this is stopping it from doing better, then what use does it have? E.g. if the inlined function does a simple Inc(Value) then it would be worse than without the inlining.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Procedure optimization problem with local variable
« Reply #16 on: June 28, 2020, 05:46:32 pm »
You should leave that to e.g. Florian to decide.
Ok - 37282.

Okoba

  • Hero Member
  • *****
  • Posts: 528
Re: Procedure optimization problem with local variable
« Reply #17 on: June 28, 2020, 06:08:34 pm »
@PascalDragon the first problem of optimizing usage of a record value needs reporting too?

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Procedure optimization problem with local variable
« Reply #18 on: June 28, 2020, 06:47:17 pm »
You already found a reasonably good solution which is the last test case in your test program.  Just assign the record field to a variable, use that variable (which the compiler will place in a register) and when the loop is done, move the value of the variable back into the record's field.    It's a bit "pedestrian" but, I believe it is preferable over using assembler.

Placing a comment stating the reason for the "acrobatics" with the record's field might be a good idea if someone other than yourself may need to maintain that code.


You cannot do that acrobatics, when the loop is a for..in loop with a record enumerator


@PascalDragon the first problem of optimizing usage of a record value needs reporting too?

They did not like it: https://bugs.freepascal.org/view.php?id=34915

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Procedure optimization problem with local variable
« Reply #19 on: June 28, 2020, 07:03:08 pm »
@PascalDragon the first problem of optimizing usage of a record value needs reporting too?

They did not like it: https://bugs.freepascal.org/view.php?id=34915

Jonas simply said to move the discussion about this to the mailing list and not to have it in the bugtracker. As you can see the bug was set to "suspended", not "won't fix", "no change required" or something like that.

Okoba

  • Hero Member
  • *****
  • Posts: 528
Re: Procedure optimization problem with local variable
« Reply #20 on: June 28, 2020, 07:25:01 pm »
I guessed there should be a bug report already, thanks @BeniBela. Did you find any workaround for now?

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Procedure optimization problem with local variable
« Reply #21 on: June 28, 2020, 07:46:07 pm »
You cannot do that acrobatics, when the loop is a for..in loop with a record enumerator
I am not surprised there are cases when that method won't produce the desired results. 

Personally, I would try different ways for each case and hopefully find one that leads the compiler to produce the code I want.  Other than that, hand coded assembly seems to be the only way to get the code optimized as desired.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018