Browse Source

* do not replace index registers with esp/rsp, resolves #40223

florian 2 years ago
parent
commit
6663d5ca63
2 changed files with 13 additions and 2 deletions
  1. 2 2
      compiler/x86/aoptx86.pas
  2. 11 0
      tests/webtbs/tw40223.pp

+ 2 - 2
compiler/x86/aoptx86.pas

@@ -23,7 +23,7 @@ unit aoptx86;
 
 {$i fpcdefs.inc}
 
-{ $define DEBUG_AOPTCPU}
+{$define DEBUG_AOPTCPU}
 
 {$ifdef EXTDEBUG}
 {$define DEBUG_AOPTCPU}
@@ -2522,7 +2522,7 @@ unit aoptx86;
           end;
 
         { Check index register }
-        if (ref.index = AOldReg) then
+        if (ref.index = AOldReg) and (getsupreg(ANewReg)<>RS_ESP) then
           begin
             ref.index := ANewReg;
             Result := True;

+ 11 - 0
tests/webtbs/tw40223.pp

@@ -0,0 +1,11 @@
+{ %opt=-O2 }
+{ %norun }
+procedure DoSomething(index, cellSize: SizeUint);
+var
+	buf: array[0 .. 127] of byte;
+begin
+	(pByte(buf) + index * cellSize)^ := 5;
+end;
+
+begin
+end.