浏览代码

* handle unrolling of for ... downto ... correctly, resolves #15668

git-svn-id: trunk@14884 -
florian 15 年之前
父节点
当前提交
092153e7ad
共有 3 个文件被更改,包括 24 次插入3 次删除
  1. 1 0
      .gitattributes
  2. 7 3
      compiler/optloop.pas
  3. 16 0
      tests/webtbs/tw15668.pp

+ 1 - 0
.gitattributes

@@ -10278,6 +10278,7 @@ tests/webtbs/tw15504.pp svneol=native#text/plain
 tests/webtbs/tw15530.pp svneol=native#text/pascal
 tests/webtbs/tw15530.pp svneol=native#text/pascal
 tests/webtbs/tw15607.pp svneol=native#text/plain
 tests/webtbs/tw15607.pp svneol=native#text/plain
 tests/webtbs/tw15619.pp svneol=native#text/plain
 tests/webtbs/tw15619.pp svneol=native#text/plain
+tests/webtbs/tw15668.pp svneol=native#text/pascal
 tests/webtbs/tw1567.pp svneol=native#text/plain
 tests/webtbs/tw1567.pp svneol=native#text/plain
 tests/webtbs/tw15690.pp svneol=native#text/plain
 tests/webtbs/tw15690.pp svneol=native#text/plain
 tests/webtbs/tw15693.pp svneol=native#text/plain
 tests/webtbs/tw15693.pp svneol=native#text/plain

+ 7 - 3
compiler/optloop.pas

@@ -127,9 +127,13 @@ unit optloop;
                     { for itself increases at the last iteration }
                     { for itself increases at the last iteration }
                     if i<unrolls then
                     if i<unrolls then
                       begin
                       begin
-                        { insert incrementation of counter var }
-                        addstatement(unrollstatement,
-                          geninlinenode(in_inc_x,false,ccallparanode.create(tfornode(node).left.getcopy,nil)));
+                        { insert incr/decrementation of counter var }
+                        if lnf_backward in tfornode(node).loopflags then
+                          addstatement(unrollstatement,
+                            geninlinenode(in_dec_x,false,ccallparanode.create(tfornode(node).left.getcopy,nil)))
+                        else
+                          addstatement(unrollstatement,
+                            geninlinenode(in_inc_x,false,ccallparanode.create(tfornode(node).left.getcopy,nil)));
                       end;
                       end;
                   end;
                   end;
                 { can we get rid of the for statement? }
                 { can we get rid of the for statement? }

+ 16 - 0
tests/webtbs/tw15668.pp

@@ -0,0 +1,16 @@
+{ %OPT=-Ooloopunroll -O2 -S2 -Cr }
+const
+  StrArray :array[0..1] of string = ('s1','s2');
+
+function FindStr(const s :string) :Integer;
+var
+  i :Integer;
+begin
+  for i := High(StrArray) downto 0 do
+    if StrArray[i] = s then Exit(i);
+  Result := -1;
+end;
+
+begin
+  FindStr('s1');
+end.