Procházet zdrojové kódy

* better code for ... downto 1 for-loops

florian před 8 měsíci
rodič
revize
798f2ba632
1 změnil soubory, kde provedl 10 přidání a 1 odebrání
  1. 10 1
      compiler/nflw.pas

+ 10 - 1
compiler/nflw.pas

@@ -2103,7 +2103,16 @@ implementation
             else
               toexpr:=t1.getcopy;
 
-            addstatement(ifstatements,cwhilerepeatnode.create(caddnode.create_internal(cond,leftcopy,toexpr),loopblock,false,true));
+            { checking against zero might improve the generated assembler,
+              doing this transformation for other values is normally not beneficial }
+            if do_loopvar_at_end and (lnf_backward in loopflags) and is_constintnode(toexpr) and (tordconstnode(toexpr).value=1) and
+              (countermin<tordconstnode(toexpr).value) then
+              begin
+                tordconstnode(toexpr).value:=tordconstnode(toexpr).value-1;
+                addstatement(ifstatements,cwhilerepeatnode.create(caddnode.create_internal(equaln,leftcopy,toexpr),loopblock,false,true))
+              end
+            else
+              addstatement(ifstatements,cwhilerepeatnode.create(caddnode.create_internal(cond,leftcopy,toexpr),loopblock,false,true));
 
             if usefromtemp then
               fromexpr:=ctemprefnode.create(fromtemp)