瀏覽代碼

* Fixed arm optimizer bug (mantis #9209). No testsuite regressions with -O2.
* Removed unused local vars.
+ test.

git-svn-id: trunk@7970 -

yury 18 年之前
父節點
當前提交
2829f4e46f
共有 3 個文件被更改,包括 35 次插入4 次删除
  1. 1 0
      .gitattributes
  2. 10 4
      compiler/arm/aoptcpu.pas
  3. 24 0
      tests/webtbs/tw9209.pp

+ 1 - 0
.gitattributes

@@ -8324,6 +8324,7 @@ tests/webtbs/tw9174.pp svneol=native#text/plain
 tests/webtbs/tw9179.pp svneol=native#text/plain
 tests/webtbs/tw9187.pp svneol=native#text/plain
 tests/webtbs/tw9190.pp svneol=native#text/plain
+tests/webtbs/tw9209.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 10 - 4
compiler/arm/aoptcpu.pas

@@ -50,8 +50,7 @@ Implementation
 
   function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
     var
-      next1, next2: tai;
-      l1, l2, shlcount: longint;
+      next1: tai;
     begin
       result := false;
       case p.typ of
@@ -110,6 +109,7 @@ Implementation
       l : longint;
       condition : tasmcond;
       hp3: tai;
+      WasLast: boolean;
       { UsedRegs, TmpUsedRegs: TRegSet; }
 
     begin
@@ -131,6 +131,7 @@ Implementation
                              xxx:
                          }
                          l:=0;
+                         WasLast:=False;
                          GetNextInstruction(p, hp1);
                          while assigned(hp1) and
                            (l<=4) and
@@ -141,6 +142,7 @@ Implementation
                               inc(l);
                               if MustBeLast(hp1) then
                                 begin
+                                  WasLast:=True;
                                   GetNextInstruction(hp1,hp1);
                                   break;
                                 end
@@ -180,13 +182,17 @@ Implementation
                                     end;
                                 end
                               else
+                                { do not perform further optimizations if there is inctructon
+                                  in block #1 which can not be optimized.
+                                 }
+                                if not WasLast then
                                 begin
                                    { check further for
                                           Bcc   xxx
-                                          <several movs 1>
+                                          <several instructions 1>
                                           B   yyy
                                   xxx:
-                                          <several movs 2>
+                                          <several instructions 2>
                                   yyy:
                                    }
                                   { hp2 points to jmp yyy }

+ 24 - 0
tests/webtbs/tw9209.pp

@@ -0,0 +1,24 @@
+{%OPT=-O2}
+
+procedure Proc1(i: integer);
+begin
+  if i = 1 then
+    Inc(i);
+end;
+
+procedure Proc2;
+begin
+  writeln('Test failed!');
+  Halt(1);
+end;
+
+var
+  i, j: integer;
+
+begin
+  if (i = 0) and (j = 0) then
+    Proc1(i)
+  else
+    Proc2;
+  writeln('Test OK.');
+end.