Browse Source

* don't do MovOpMov2MovOp optimization reducing bit width of the operation if symbols are involved, resolves #40269

florian 3 months ago
parent
commit
7afde9fe77
2 changed files with 13 additions and 0 deletions
  1. 4 0
      compiler/x86/aoptx86.pas
  2. 9 0
      tests/webtbs/tw40269.pp

+ 4 - 0
compiler/x86/aoptx86.pas

@@ -5266,6 +5266,10 @@ unit aoptx86;
               ((topsize2memsize[taicpu(hp1).opsize]<= topsize2memsize[taicpu(hp2).opsize]) or
                { opsize matters for these opcodes, we could probably work around this, but it is not worth the effort }
                ((taicpu(hp1).opcode<>A_SHL) and (taicpu(hp1).opcode<>A_SHR) and (taicpu(hp1).opcode<>A_SAR))
+              ) and
+              { if ref contains a symbol, we cannot change its size to a smaller size }
+              ((taicpu(p).oper[0]^.typ<>top_ref) or (taicpu(p).oper[0]^.ref^.symbol=nil) or
+               (topsize2memsize[taicpu(p).opsize]<=topsize2memsize[taicpu(hp2).opsize])
               )
 {$ifdef i386}
               { byte registers of esi, edi, ebp, esp are not available on i386 }

+ 9 - 0
tests/webtbs/tw40269.pp

@@ -0,0 +1,9 @@
+{ %opt=-O2 }
+var
+	a, b: int32;
+	x, y: byte;
+begin
+	x := PtrUint(@a) mod 32;
+	y := PtrUint(@b) mod 32;
+	writeln(x, ' ', y);
+end.