瀏覽代碼

* do for-loop unrolling after for-loop simplification, resolves #36589

git-svn-id: trunk@43999 -
florian 5 年之前
父節點
當前提交
069e040e49
共有 3 個文件被更改,包括 26 次插入17 次删除
  1. 1 0
      .gitattributes
  2. 19 17
      compiler/nflw.pas
  3. 6 0
      tests/webtbs/tw36589.pp

+ 1 - 0
.gitattributes

@@ -17956,6 +17956,7 @@ tests/webtbs/tw3650.pp svneol=native#text/plain
 tests/webtbs/tw3653.pp svneol=native#text/plain
 tests/webtbs/tw36544a.pp svneol=native#text/pascal
 tests/webtbs/tw36544b.pp svneol=native#text/pascal
+tests/webtbs/tw36589.pp svneol=native#text/pascal
 tests/webtbs/tw3661.pp svneol=native#text/plain
 tests/webtbs/tw3666.pp svneol=native#text/plain
 tests/webtbs/tw3669.pp svneol=native#text/plain

+ 19 - 17
compiler/nflw.pas

@@ -1690,8 +1690,26 @@ implementation
 
          set_varstate(left,vs_written,[]);
 
+         { Make sure that the loop var and the
+           from and to values are compatible types }
+         if not(m_iso in current_settings.modeswitches) then
+           rangedef:=left.resultdef
+         else
+           rangedef:=get_iso_range_type(left.resultdef);
+
+         check_ranges(right.fileinfo,right,rangedef);
+         inserttypeconv(right,rangedef);
+
+         check_ranges(t1.fileinfo,t1,rangedef);
+         inserttypeconv(t1,rangedef);
+
+         if assigned(t2) then
+           typecheckpass(t2);
+         result:=simplify(false);
+
          { loop unrolling }
-         if (cs_opt_loopunroll in current_settings.optimizerswitches) and
+         if not(assigned(result)) and
+           (cs_opt_loopunroll in current_settings.optimizerswitches) and
            assigned(t2) and
            { statements must be error free }
            not(nf_error in t2.flags) then
@@ -1709,22 +1727,6 @@ implementation
                end;
            end;
 
-         { Make sure that the loop var and the
-           from and to values are compatible types }
-         if not(m_iso in current_settings.modeswitches) then
-           rangedef:=left.resultdef
-         else
-           rangedef:=get_iso_range_type(left.resultdef);
-
-         check_ranges(right.fileinfo,right,rangedef);
-         inserttypeconv(right,rangedef);
-
-         check_ranges(t1.fileinfo,t1,rangedef);
-         inserttypeconv(t1,rangedef);
-
-         if assigned(t2) then
-           typecheckpass(t2);
-         result:=simplify(false);
       end;
 
 

+ 6 - 0
tests/webtbs/tw36589.pp

@@ -0,0 +1,6 @@
+var k : longint;
+begin
+     for k:=1 downto 10 do
+     begin
+     end;
+end.