Browse Source

Fixed bug in new TEST optimisation where a FLAGS check always returned "in use"

J. Gareth "Curious Kit" Moreton 3 years ago
parent
commit
be448e29f6
1 changed files with 6 additions and 1 deletions
  1. 6 1
      compiler/x86/aoptx86.pas

+ 6 - 1
compiler/x86/aoptx86.pas

@@ -4519,6 +4519,8 @@ unit aoptx86;
 
                             { Only remove the second test if no jumps or other conditional instructions follow }
                             TransferUsedRegs(TmpUsedRegs);
+                            UpdateUsedRegs(TmpUsedRegs, tai(p.Next));
+                            UpdateUsedRegs(TmpUsedRegs, tai(hp1.Next));
                             if not RegUsedAfterInstruction(NR_DEFAULTFLAGS, p_dist, TmpUsedRegs) then
                               RemoveInstruction(p_dist);
 
@@ -4559,12 +4561,15 @@ unit aoptx86;
                       TAsmLabel(taicpu(hp1_dist).oper[0]^.ref^.symbol).DecRefs;
 
                     DebugMsg(SPeepholeOptimization + 'TEST/JNE/TEST/JNE merged', p);
+                    RemoveInstruction(hp1_dist);
+
                     { Only remove the second test if no jumps or other conditional instructions follow }
                     TransferUsedRegs(TmpUsedRegs);
+                    UpdateUsedRegs(TmpUsedRegs, tai(p.Next));
+                    UpdateUsedRegs(TmpUsedRegs, tai(hp1.Next));
                     if not RegUsedAfterInstruction(NR_DEFAULTFLAGS, p_dist, TmpUsedRegs) then
                       RemoveInstruction(p_dist);
 
-                    RemoveInstruction(hp1_dist);
                     Result := True;
                     Exit;
                   end;