mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-26 23:30:29 +02:00
* moved transformation of "mul by power-of-2" to shl from type check
pass to pass 1 (where most optimizing transformations are located, and because the way it's written it goes wrong if left and right are a constant, and I'm working on moving the simplify code after the typechecking code so the resulttype for constant and non-constant expressions can be the same) git-svn-id: trunk@10396 -
This commit is contained in:
parent
179b840cea
commit
59ca0153e7
@ -761,7 +761,6 @@ implementation
|
|||||||
hp : tnode;
|
hp : tnode;
|
||||||
rd,ld,nd : tdef;
|
rd,ld,nd : tdef;
|
||||||
hsym : tfieldvarsym;
|
hsym : tfieldvarsym;
|
||||||
i : longint;
|
|
||||||
llow,lhigh,
|
llow,lhigh,
|
||||||
rlow,rhigh : tconstexprint;
|
rlow,rhigh : tconstexprint;
|
||||||
strtype : tstringtype;
|
strtype : tstringtype;
|
||||||
@ -945,29 +944,6 @@ implementation
|
|||||||
{ if both are orddefs then check sub types }
|
{ if both are orddefs then check sub types }
|
||||||
else if (ld.typ=orddef) and (rd.typ=orddef) then
|
else if (ld.typ=orddef) and (rd.typ=orddef) then
|
||||||
begin
|
begin
|
||||||
{ optimize multiplacation by a power of 2 }
|
|
||||||
if not(cs_check_overflow in current_settings.localswitches) and
|
|
||||||
(nodetype = muln) and
|
|
||||||
(((left.nodetype = ordconstn) and
|
|
||||||
ispowerof2(tordconstnode(left).value,i)) or
|
|
||||||
((right.nodetype = ordconstn) and
|
|
||||||
ispowerof2(tordconstnode(right).value,i))) then
|
|
||||||
begin
|
|
||||||
if left.nodetype = ordconstn then
|
|
||||||
begin
|
|
||||||
tordconstnode(left).value := i;
|
|
||||||
result := cshlshrnode.create(shln,right,left);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
tordconstnode(right).value := i;
|
|
||||||
result := cshlshrnode.create(shln,left,right);
|
|
||||||
end;
|
|
||||||
left := nil;
|
|
||||||
right := nil;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ set for & and | operations in macpas mode: they only work on }
|
{ set for & and | operations in macpas mode: they only work on }
|
||||||
{ booleans, and always short circuit evaluation }
|
{ booleans, and always short circuit evaluation }
|
||||||
if (nf_short_bool in flags) then
|
if (nf_short_bool in flags) then
|
||||||
@ -2376,10 +2352,11 @@ implementation
|
|||||||
{$ifdef addstringopt}
|
{$ifdef addstringopt}
|
||||||
hp : tnode;
|
hp : tnode;
|
||||||
{$endif addstringopt}
|
{$endif addstringopt}
|
||||||
lt,rt : tnodetype;
|
|
||||||
rd,ld : tdef;
|
rd,ld : tdef;
|
||||||
newstatement : tstatementnode;
|
newstatement : tstatementnode;
|
||||||
temp : ttempcreatenode;
|
temp : ttempcreatenode;
|
||||||
|
i : longint;
|
||||||
|
lt,rt : tnodetype;
|
||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
|
|
||||||
@ -2422,6 +2399,29 @@ implementation
|
|||||||
{ if both are orddefs then check sub types }
|
{ if both are orddefs then check sub types }
|
||||||
else if (ld.typ=orddef) and (rd.typ=orddef) then
|
else if (ld.typ=orddef) and (rd.typ=orddef) then
|
||||||
begin
|
begin
|
||||||
|
{ optimize multiplacation by a power of 2 }
|
||||||
|
if not(cs_check_overflow in current_settings.localswitches) and
|
||||||
|
(nodetype = muln) and
|
||||||
|
(((left.nodetype = ordconstn) and
|
||||||
|
ispowerof2(tordconstnode(left).value,i)) or
|
||||||
|
((right.nodetype = ordconstn) and
|
||||||
|
ispowerof2(tordconstnode(right).value,i))) then
|
||||||
|
begin
|
||||||
|
if left.nodetype = ordconstn then
|
||||||
|
begin
|
||||||
|
tordconstnode(left).value := i;
|
||||||
|
result := cshlshrnode.create(shln,right,left);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
tordconstnode(right).value := i;
|
||||||
|
result := cshlshrnode.create(shln,left,right);
|
||||||
|
end;
|
||||||
|
left := nil;
|
||||||
|
right := nil;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
{ 2 booleans ? }
|
{ 2 booleans ? }
|
||||||
if is_boolean(ld) and is_boolean(rd) then
|
if is_boolean(ld) and is_boolean(rd) then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user