mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 10:09:22 +02:00
* Strength reduction optimization: - Use a temp for complex loop start values to prevent double evaluation.
- For slow CPUs perform the optimization for all sizes of array elements.
This commit is contained in:
parent
6bf4c7a68d
commit
7388735b11
@ -350,7 +350,7 @@ unit optloop;
|
|||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
tempnode : ttempcreatenode;
|
tempnode,startvaltemp : ttempcreatenode;
|
||||||
dummy : longint;
|
dummy : longint;
|
||||||
nn : tnode;
|
nn : tnode;
|
||||||
nt : tnodetype;
|
nt : tnodetype;
|
||||||
@ -453,10 +453,13 @@ unit optloop;
|
|||||||
{ direct array access? }
|
{ direct array access? }
|
||||||
((tvecnode(n).left.nodetype=loadn) or
|
((tvecnode(n).left.nodetype=loadn) or
|
||||||
{ ... or loop invariant expression? }
|
{ ... or loop invariant expression? }
|
||||||
is_loop_invariant(tfornode(arg),tvecnode(n).right)) and
|
is_loop_invariant(tfornode(arg),tvecnode(n).right))
|
||||||
|
{$if not (defined(cpu16bitalu) or defined(cpu8bitalu))}
|
||||||
{ removing the multiplication is only worth the
|
{ removing the multiplication is only worth the
|
||||||
effort if it's not a simple shift }
|
effort if it's not a simple shift }
|
||||||
not(ispowerof2(tcgvecnode(n).get_mul_size,dummy)) then
|
and not(ispowerof2(tcgvecnode(n).get_mul_size,dummy))
|
||||||
|
{$endif}
|
||||||
|
then
|
||||||
begin
|
begin
|
||||||
changedforloop:=true;
|
changedforloop:=true;
|
||||||
{ did we use the same expression before already? }
|
{ did we use the same expression before already? }
|
||||||
@ -487,6 +490,8 @@ unit optloop;
|
|||||||
cordconstnode.create(tcgvecnode(n).get_mul_size,sizeuinttype,false),nil))));
|
cordconstnode.create(tcgvecnode(n).get_mul_size,sizeuinttype,false),nil))));
|
||||||
|
|
||||||
addstatement(initcodestatements,tempnode);
|
addstatement(initcodestatements,tempnode);
|
||||||
|
|
||||||
|
startvaltemp:=maybereplacewithtemp(tfornode(arg).right,initcode,initcodestatements,tfornode(arg).right.resultdef.size,true);
|
||||||
nn:=caddrnode.create(
|
nn:=caddrnode.create(
|
||||||
cvecnode.create(tvecnode(n).left.getcopy,tfornode(arg).right.getcopy)
|
cvecnode.create(tvecnode(n).left.getcopy,tfornode(arg).right.getcopy)
|
||||||
);
|
);
|
||||||
@ -508,6 +513,8 @@ unit optloop;
|
|||||||
n:=ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),n.resultdef);
|
n:=ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),n.resultdef);
|
||||||
|
|
||||||
{ ... and add a temp. release node }
|
{ ... and add a temp. release node }
|
||||||
|
if startvaltemp<>nil then
|
||||||
|
addstatement(deletecodestatements,ctempdeletenode.create(startvaltemp));
|
||||||
addstatement(deletecodestatements,ctempdeletenode.create(tempnode));
|
addstatement(deletecodestatements,ctempdeletenode.create(tempnode));
|
||||||
end;
|
end;
|
||||||
{ Copy the nf_write,nf_modify flags to the new deref node of the temp.
|
{ Copy the nf_write,nf_modify flags to the new deref node of the temp.
|
||||||
|
Loading…
Reference in New Issue
Block a user