Browse Source

* x86: Fixed bug in TEST/JNE/TEST/JNE optimisation that caused bad code to be generated under -O3

J. Gareth "Curious Kit" Moreton 2 years ago
parent
commit
699db16fe4
1 changed files with 10 additions and 1 deletions
  1. 10 1
      compiler/x86/aoptx86.pas

+ 10 - 1
compiler/x86/aoptx86.pas

@@ -5313,7 +5313,6 @@ unit aoptx86;
         { Search for:
             test  $x,(reg/ref)
             jne   @lbl1
-            ...
             test  $y,(reg/ref) (same register or reference)
             jne   @lbl1
 
@@ -5481,6 +5480,16 @@ unit aoptx86;
                         (FirstValue = -1) or
                         (SecondValue = -1) or
                         MatchOperand(taicpu(hp1_dist).oper[0]^, taicpu(hp1).oper[0]^)
+                      ) and
+                      (
+                        { In this situation, the TEST/JNE pairs must be adjacent (fixes #40366) }
+
+                        { Always adjacent under -O2 and under }
+                        not(cs_opt_level3 in current_settings.optimizerswitches) or
+                        (
+                          GetNextInstruction(hp1, hp1_last) and
+                          (hp1_last = p_dist)
+                        )
                       ) then
                       begin
                         { Same jump location... can be a register since nothing's changed }