Browse Source

Fix interaction between peephole optimizers on ARM

Up until now DataMov2Data could be run on an strb generated by
AndStrb2Strb.

Code like this:

and  reg0, reg1, #255
strb reg0, [r13]
mov  reg2,reg1

would get transformed into:

strb reg2, [r13]

which is clearly wrong. The problem was that DataMov2Data expected that
it's first parameter is an instruction which loads new data into
oper[0]. With the introduction of AndStrb2Strb this wasn't true anymore.

This fix now checks if the first register is actually written to, this
is done by using regLoadedWithNewValue.

git-svn-id: trunk@22622 -
masta 13 years ago
parent
commit
29bac200dd
1 changed files with 9 additions and 1 deletions
  1. 9 1
      compiler/arm/aoptcpu.pas

+ 9 - 1
compiler/arm/aoptcpu.pas

@@ -321,7 +321,15 @@ Implementation
          not (
            (taicpu(p).opcode in [A_MLA, A_MUL]) and
            (taicpu(p).oper[1]^.reg = taicpu(movp).oper[0]^.reg)
-         ) then
+         ) and
+         { Take care to only do this for instructions which REALLY load to the first register.
+           Otherwise
+             str reg0, [reg1]
+             mov reg2, reg0
+           will be optimized to
+             str reg2, [reg1]
+         }
+         not (regLoadedWithNewValue(taicpu(p).oper[0]^.reg, p)) then
         begin
           dealloc:=FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(movp.Next));
           if assigned(dealloc) then