* x86: Fixed peephole optimization introduced in r44233. tb0219 and tb0548 tests have failed with -O2 since then.

* Added variants of the tb0219 and tb0548 tests with forced -O2.

git-svn-id: trunk@45291 -
This commit is contained in:
yury 2020-05-06 14:18:44 +00:00
parent 75ce122d36
commit c1d124d497
4 changed files with 30 additions and 25 deletions

2
.gitattributes vendored
View File

@ -12811,6 +12811,7 @@ tests/tbs/tb0216.pp svneol=native#text/plain
tests/tbs/tb0217.pp svneol=native#text/plain
tests/tbs/tb0218.pp svneol=native#text/plain
tests/tbs/tb0219.pp svneol=native#text/plain
tests/tbs/tb0219a.pp svneol=native#text/plain
tests/tbs/tb0220.pp svneol=native#text/plain
tests/tbs/tb0221.pp svneol=native#text/plain
tests/tbs/tb0222.pp svneol=native#text/plain
@ -13138,6 +13139,7 @@ tests/tbs/tb0545.pp svneol=native#text/plain
tests/tbs/tb0546.pp svneol=native#text/plain
tests/tbs/tb0547.pp svneol=native#text/plain
tests/tbs/tb0548.pp svneol=native#text/plain
tests/tbs/tb0548a.pp svneol=native#text/plain
tests/tbs/tb0549.pp svneol=native#text/plain
tests/tbs/tb0550.pp svneol=native#text/plain
tests/tbs/tb0550a.pp svneol=native#text/plain

View File

@ -1821,8 +1821,21 @@ unit aoptx86;
function TX86AsmOptimizer.OptPass1MOV(var p : tai) : boolean;
var
hp1, hp2: tai;
procedure convert_mov_value(signed_movop: tasmop; max_value: tcgint); inline;
begin
if taicpu(hp1).opcode = signed_movop then
begin
if taicpu(p).oper[0]^.val > max_value shr 1 then
taicpu(p).oper[0]^.val:=taicpu(p).oper[0]^.val - max_value - 1 { Convert to signed }
end
else
taicpu(p).oper[0]^.val:=taicpu(p).oper[0]^.val and max_value; { Trim to unsigned }
end;
var
hp1, hp2, hp4: tai;
GetNextInstruction_p, TempRegUsed: Boolean;
PreMessage, RegName1, RegName2, InputVal, MaskNum: string;
NewSize: topsize;
@ -1987,56 +2000,38 @@ unit aoptx86;
case taicpu(hp1).opsize of
S_BW:
begin
if (taicpu(hp1).opcode = A_MOVSX) and
(taicpu(p).oper[0]^.val > $7F) then
taicpu(p).oper[0]^.val := taicpu(p).oper[0]^.val - $100; { Convert to signed }
convert_mov_value(A_MOVSX, $FF);
setsubreg(taicpu(p).oper[1]^.reg, R_SUBW);
taicpu(p).opsize := S_W;
end;
S_BL:
begin
if (taicpu(hp1).opcode = A_MOVSX) and
(taicpu(p).oper[0]^.val > $7F) then
taicpu(p).oper[0]^.val := taicpu(p).oper[0]^.val - $100; { Convert to signed }
convert_mov_value(A_MOVSX, $FF);
setsubreg(taicpu(p).oper[1]^.reg, R_SUBD);
taicpu(p).opsize := S_L;
end;
S_WL:
begin
if (taicpu(hp1).opcode = A_MOVSX) and
(taicpu(p).oper[0]^.val > $7FFF) then
taicpu(p).oper[0]^.val := taicpu(p).oper[0]^.val - $10000; { Convert to signed }
convert_mov_value(A_MOVSX, $FFFF);
setsubreg(taicpu(p).oper[1]^.reg, R_SUBD);
taicpu(p).opsize := S_L;
end;
{$ifdef x86_64}
S_BQ:
begin
if (taicpu(hp1).opcode = A_MOVSX) and
(taicpu(p).oper[0]^.val > $7F) then
taicpu(p).oper[0]^.val := taicpu(p).oper[0]^.val - $100; { Convert to signed }
convert_mov_value(A_MOVSX, $FF);
setsubreg(taicpu(p).oper[1]^.reg, R_SUBQ);
taicpu(p).opsize := S_Q;
end;
S_WQ:
begin
if (taicpu(hp1).opcode = A_MOVSX) and
(taicpu(p).oper[0]^.val > $7FFF) then
taicpu(p).oper[0]^.val := taicpu(p).oper[0]^.val - $10000; { Convert to signed }
convert_mov_value(A_MOVSX, $FFFF);
setsubreg(taicpu(p).oper[1]^.reg, R_SUBQ);
taicpu(p).opsize := S_Q;
end;
S_LQ:
begin
if (taicpu(hp1).opcode = A_MOVSXD) and { Note it's MOVSXD, not MOVSX }
(taicpu(p).oper[0]^.val > $7FFFFFFF) then
taicpu(p).oper[0]^.val := taicpu(p).oper[0]^.val - $100000000; { Convert to signed }
convert_mov_value(A_MOVSXD, $FFFFFFFF); { Note it's MOVSXD, not MOVSX }
setsubreg(taicpu(p).oper[1]^.reg, R_SUBQ);
taicpu(p).opsize := S_Q;
end;

4
tests/tbs/tb0219a.pp Normal file
View File

@ -0,0 +1,4 @@
{ %OPT=-O2 }
{ Additional test with -O2 since higher optimizaton levels are
smart enough to completely remove the test code }
{$I tb0219.pp}

4
tests/tbs/tb0548a.pp Normal file
View File

@ -0,0 +1,4 @@
{ %OPT=-O2 }
{ Additional test with -O2 since higher optimizaton levels are
smart enough to completely remove the test code }
{$I tb0548.pp}