diff --git a/compiler/optloop.pas b/compiler/optloop.pas index 3b848ab96e..0000b3048b 100644 --- a/compiler/optloop.pas +++ b/compiler/optloop.pas @@ -23,6 +23,8 @@ unit optloop; {$i fpcdefs.inc} +{ $define DEBUG_OPTSTRENGTH} + interface uses @@ -388,7 +390,7 @@ unit optloop; { direct array access? } ((tvecnode(n).left.nodetype=loadn) or { ... or loop invariant expression? } - is_loop_invariant(tfornode(arg),tvecnode(n).left)) and + is_loop_invariant(tfornode(arg),tvecnode(n).right)) and { removing the multiplication is only worth the effort if it's not a simple shift } not(ispowerof2(tcgvecnode(n).get_mul_size,dummy)) then @@ -397,6 +399,12 @@ unit optloop; { did we use the same expression before already? } if not(findpreviousstrengthreduction) then begin +{$ifdef DEBUG_OPTSTRENGTH} + writeln('**********************************************************************************'); + writeln('Found expression for strength reduction: '); + printnode(n); + writeln('**********************************************************************************'); +{$endif DEBUG_OPTSTRENGTH} tempnode:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true); templist.Add(tempnode); @@ -476,10 +484,10 @@ unit optloop; node:=fornode; loopcode:=internalstatements(loopcodestatements); - addstatement(loopcodestatements,calccode); addstatement(loopcodestatements,tfornode(node).t2); tfornode(node).t2:=loopcode; do_firstpass(node); + addstatement(loopcodestatements,calccode); result:=internalstatements(newcodestatements); addstatement(newcodestatements,initcode); @@ -501,7 +509,7 @@ unit optloop; { do we have DFA available? } if pi_dfaavailable in current_procinfo.flags then begin - CalcDefSum(n); + CalcDefSum(tfornode(n).t2); end; containsnestedforloop:=false; @@ -526,3 +534,4 @@ unit optloop; end; end. +