From 29429cca3c159fe51c58f0c9b44724b7daced5c5 Mon Sep 17 00:00:00 2001 From: nickysn Date: Mon, 1 May 2017 11:45:23 +0000 Subject: [PATCH] + mask the shift/rotate count value in the rol/ror/sar inline nodes, before checking for 0, so that things like sar(int32,32) can be optimized to int32, just like sar(int32,0) git-svn-id: trunk@36031 - --- compiler/ninl.pas | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/compiler/ninl.pas b/compiler/ninl.pas index de5d3ee9b0..44d38b3467 100644 --- a/compiler/ninl.pas +++ b/compiler/ninl.pas @@ -1962,6 +1962,15 @@ implementation assigned(tcallparanode(left).right) then begin vl:=tordconstnode(tcallparanode(left).left).value; + if forinline then + case resultdef.size of + 1,2,4: + vl:=vl and byte($1f); + 8: + vl:=vl and byte($3f); + else + internalerror(2013122302); + end; if (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then begin def:=tcallparanode(tcallparanode(left).right).left.resultdef; @@ -2024,6 +2033,22 @@ implementation assigned(tcallparanode(left).right) then begin vl:=tordconstnode(tcallparanode(left).left).value; + if forinline then + case resultdef.size of + { unlike shifts, for rotates, when masking out the higher bits + of the rotate count, we go all the way down to byte, because + it doesn't matter, it produces the same result, since it's a rotate } + 1: + vl:=vl and byte($07); + 2: + vl:=vl and byte($0f); + 4: + vl:=vl and byte($1f); + 8: + vl:=vl and byte($3f); + else + internalerror(2013122302); + end; if (tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn) then begin def:=tcallparanode(tcallparanode(left).right).left.resultdef;