Browse Source

Fix incorrect AVR optimization.

git-svn-id: trunk@32441 -
Jeppe Johansen 9 years ago
parent
commit
baae6ec169
1 changed files with 5 additions and 1 deletions
  1. 5 1
      compiler/avr/aoptcpu.pas

+ 5 - 1
compiler/avr/aoptcpu.pas

@@ -180,7 +180,7 @@ Implementation
                                         A_LSL,A_LSR,
                                         A_LSL,A_LSR,
                                         A_OR,A_ORI,A_ROL,A_ROR])))) or
                                         A_OR,A_ORI,A_ROL,A_ROR])))) or
                (MatchInstruction(hp1, A_CPI) and
                (MatchInstruction(hp1, A_CPI) and
-                (taicpu(p).opcode in [A_ANDI,A_ORI]) and
+                (taicpu(p).opcode = A_ANDI) and
                 (taicpu(p).oper[1]^.typ=top_const) and
                 (taicpu(p).oper[1]^.typ=top_const) and
                 (taicpu(hp1).oper[1]^.typ=top_const) and
                 (taicpu(hp1).oper[1]^.typ=top_const) and
                 (taicpu(p).oper[1]^.val=taicpu(hp1).oper[1]^.val))) and
                 (taicpu(p).oper[1]^.val=taicpu(hp1).oper[1]^.val))) and
@@ -208,6 +208,10 @@ Implementation
                   end;
                   end;
                 }
                 }
 
 
+                // If we compare to the same value we are masking then invert the comparison
+                if (taicpu(hp1).opcode=A_CPI) then
+                  taicpu(hp2).condition:=inverse_cond(taicpu(hp2).condition);
+
                 asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
                 asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
                 asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,hp2), hp2);
                 asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,hp2), hp2);
                 IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);
                 IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);