From 5eb59196d528f79ee3502e28b7bf3cf5f1232449 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 17 Feb 2018 12:45:17 +0000 Subject: [PATCH] * remove sequential moves to the same register + test git-svn-id: trunk@38267 - --- .gitattributes | 1 + compiler/x86/aoptx86.pas | 21 +++++++++++++++++++++ tests/webtbs/tw15438.pp | 29 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/webtbs/tw15438.pp diff --git a/.gitattributes b/.gitattributes index 29b378cd9a..98bd8661fe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14953,6 +14953,7 @@ tests/webtbs/tw1539.pp svneol=native#text/plain tests/webtbs/tw15391.pp svneol=native#text/plain tests/webtbs/tw15391a.pp svneol=native#text/plain tests/webtbs/tw15415.pp svneol=native#text/plain +tests/webtbs/tw15438.pp svneol=native#text/pascal tests/webtbs/tw15446.pp svneol=native#text/plain tests/webtbs/tw15453a.pp svneol=native#text/plain tests/webtbs/tw15467.pp svneol=native#text/pascal diff --git a/compiler/x86/aoptx86.pas b/compiler/x86/aoptx86.pas index 3df3edc7eb..31a7969233 100644 --- a/compiler/x86/aoptx86.pas +++ b/compiler/x86/aoptx86.pas @@ -1674,6 +1674,27 @@ unit aoptx86; taicpu(hp1).fileinfo := taicpu(p).fileinfo; DebugMsg(SPeepholeOptimization + 'MovMov2MovMov 1',p); end + { + mov* x,reg1 + mov* y,reg1 + + to + + mov* y,reg1 + } + else if (taicpu(p).oper[1]^.typ=top_reg) and + MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^) and + not(RegInOp(taicpu(p).oper[1]^.reg,taicpu(hp1).oper[0]^)) then + begin + DebugMsg(SPeepholeOptimization + 'MovMov2Mov 4 done',p); + { take care of the register (de)allocs following p } + UpdateUsedRegs(tai(p.next)); + asml.remove(p); + p.free; + p:=hp1; + Result:=true; + exit; + end; end else if (taicpu(p).oper[1]^.typ = top_reg) and diff --git a/tests/webtbs/tw15438.pp b/tests/webtbs/tw15438.pp new file mode 100644 index 0000000000..e3fa09070c --- /dev/null +++ b/tests/webtbs/tw15438.pp @@ -0,0 +1,29 @@ +program tbSwapEndian; + +{$mode objfpc} + +uses + sysutils; + +function InlineSwapEndian(const AValue: QWord): QWord;inline; + begin + result := (qword(SwapEndian(lo(avalue))) shl 32) or SwapEndian(hi(avalue)); + end; + +var + q : QWord; + +procedure Check; +begin + q := $0102030405060708; + q := InlineSwapEndian(q); +end; + +begin + q:=0; + Check; + if q <> $0807060504030201 then begin + writeln(format('failed Swap - expected $0807060504030201, got %x',[q])); + halt(1); + end; +end.