Browse Source

* fixed tw4266

git-svn-id: trunk@1317 -
Jonas Maebe 20 years ago
parent
commit
8471e10137
3 changed files with 67 additions and 7 deletions
  1. 1 0
      .gitattributes
  2. 36 7
      compiler/i386/csopt386.pas
  3. 30 0
      tests/webtbs/tw4266.pp

+ 1 - 0
.gitattributes

@@ -6305,6 +6305,7 @@ tests/webtbs/tw4240.pp svneol=native#text/plain
 tests/webtbs/tw4247.pp svneol=native#text/plain
 tests/webtbs/tw4247.pp svneol=native#text/plain
 tests/webtbs/tw4253.pp svneol=native#text/plain
 tests/webtbs/tw4253.pp svneol=native#text/plain
 tests/webtbs/tw4260.pp svneol=native#text/plain
 tests/webtbs/tw4260.pp svneol=native#text/plain
+tests/webtbs/tw4266.pp -text
 tests/webtbs/tw4272.pp svneol=native#text/plain
 tests/webtbs/tw4272.pp svneol=native#text/plain
 tests/webtbs/tw4277.pp svneol=native#text/plain
 tests/webtbs/tw4277.pp svneol=native#text/plain
 tests/webtbs/tw4294.pp svneol=native#text/plain
 tests/webtbs/tw4294.pp svneol=native#text/plain

+ 36 - 7
compiler/i386/csopt386.pas

@@ -409,7 +409,7 @@ var
 
 
 var
 var
   prevreginfo: toptreginfo;
   prevreginfo: toptreginfo;
-  hp2, hp3{, EndMod},highPrev, orgPrev: tai;
+  hp2, hp3{, EndMod},highPrev, orgPrev, pprev: tai;
   {Cnt,} OldNrofMods: Longint;
   {Cnt,} OldNrofMods: Longint;
   startRegInfo, OrgRegInfo, HighRegInfo: toptreginfo;
   startRegInfo, OrgRegInfo, HighRegInfo: toptreginfo;
   regModified, lastregloadremoved: array[RS_EAX..RS_ESP] of boolean;
   regModified, lastregloadremoved: array[RS_EAX..RS_ESP] of boolean;
@@ -439,6 +439,7 @@ begin {CheckSequence}
   regsNotRead := [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESP,RS_EBP,RS_EDI,RS_ESI];
   regsNotRead := [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESP,RS_EBP,RS_EDI,RS_ESI];
   regsStillValid := regsNotRead;
   regsStillValid := regsNotRead;
   GetLastInstruction(p, prev);
   GetLastInstruction(p, prev);
+  pprev := prev;
   tmpreg:=RS_INVALID;
   tmpreg:=RS_INVALID;
   regCounter := getNextRegToTest(prev,tmpreg);
   regCounter := getNextRegToTest(prev,tmpreg);
   while (regcounter <> RS_INVALID) do
   while (regcounter <> RS_INVALID) do
@@ -519,17 +520,45 @@ begin {CheckSequence}
           if not flagResultsNeeded then
           if not flagResultsNeeded then
             flagResultsNeeded := ptaiprop(hp3.optinfo)^.FlagsUsed;
             flagResultsNeeded := ptaiprop(hp3.optinfo)^.FlagsUsed;
           inc(Found);
           inc(Found);
-          if not GetNextInstruction(hp2, hp2) or
-             not GetNextInstruction(hp3, hp3) then
-            break;
+          if (Found <> OldNrofMods) then
+            if not GetNextInstruction(hp2, hp2) or
+               not GetNextInstruction(hp3, hp3) then
+              break;
         end;
         end;
 
 
+      getnextinstruction(hp3,hp3);
+{
+a) movl  -4(%ebp),%edx
+   movl -12(%ebp),%ecx
+   ...
+   movl  -8(%ebp),%eax
+   movl -12(%ebp),%edx (marked as removable)
+   movl  (%eax,%edx),%eax (replaced by "movl (%eax,%ecx),%eax")
+   ...
+   movl  -8(%ebp),%eax
+   movl -12(%ebp),%edx
+   movl  (%eax,%edx),%eax
+   movl  (%edx),%edx
+
+-> the "movl -12(ebp),%edx" can't be removed in the last sequence, because
+   edx has not been replaced with ecx there, and edx is still used after the
+   sequence
+
+b) tests/webtbs/tw4266.pp
+}
+
       for regCounter2 := RS_EAX to RS_EDI do
       for regCounter2 := RS_EAX to RS_EDI do
         if (reginfo.new2OldReg[regCounter2] <> RS_INVALID) and
         if (reginfo.new2OldReg[regCounter2] <> RS_INVALID) and
            (regCounter2 in ptaiprop(hp3.optinfo)^.usedRegs) and
            (regCounter2 in ptaiprop(hp3.optinfo)^.usedRegs) and
-           not regLoadedWithNewValue(regCounter2,false,hp3) and
-           lastregloadremoved[regcounter2] then
-          found := 0;
+           { case a) above }
+           ((not regLoadedWithNewValue(regCounter2,false,hp3) and
+             lastregloadremoved[regcounter2]) or
+           { case b) above }
+            ((ptaiprop(pprev.optinfo)^.regs[regcounter2].wstate <>
+              ptaiprop(hp2.optinfo)^.regs[regcounter2].wstate))) then
+          begin
+            found := 0;
+          end;
 
 
       if checkingPrevSequences then
       if checkingPrevSequences then
         begin
         begin

+ 30 - 0
tests/webtbs/tw4266.pp

@@ -0,0 +1,30 @@
+{ %OPT=-O-G2p3 -Sd}
+
+var
+  c: array[1..10] of integer;
+  b, a: array[1..10, 1..10] of integer;
+
+procedure rec(k: integer);
+var i: integer;
+begin
+  for i := 1 to c[k] do
+    if a[k, b[k, i]] = 0 then
+    begin
+      //writeln(i, ' ', k);
+      a[k, b[k, i]]:= 1;
+      a[b[k, i], k]:= 1;
+      rec(b[k, i]);
+    end;
+end;
+
+begin
+  fillchar(a, sizeof(a), 0);
+  c[1] := 2;
+  c[2] := 2;
+  c[3] := 2;
+  b[1, 1] := 2; b[1, 2] := 3;
+  b[2, 1] := 1; b[2, 2] := 3;
+  b[3, 1] := 1; b[3, 2] := 2;
+  rec(1);
+end.
+