diff --git a/.gitattributes b/.gitattributes index e0165d6ba8..aa8f3ef9bf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index 12742e3773..1d72e847fd 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -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; diff --git a/tests/tbs/tb0219a.pp b/tests/tbs/tb0219a.pp new file mode 100644 index 0000000000..1c49bac978 --- /dev/null +++ b/tests/tbs/tb0219a.pp @@ -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} diff --git a/tests/tbs/tb0548a.pp b/tests/tbs/tb0548a.pp new file mode 100644 index 0000000000..924479cd4a --- /dev/null +++ b/tests/tbs/tb0548a.pp @@ -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}