mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-25 12:18:20 +02:00
+ simplify shl/shr x, if (x mod bitsizeof(left))=0
git-svn-id: trunk@26628 -
This commit is contained in:
parent
b1f54b2853
commit
cd235d8409
@ -578,47 +578,58 @@ implementation
|
|||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
{ constant folding }
|
{ constant folding }
|
||||||
if is_constintnode(left) and is_constintnode(right) then
|
if is_constintnode(right) then
|
||||||
begin
|
begin
|
||||||
if forinline then
|
if forinline then
|
||||||
|
begin
|
||||||
|
{ shl/shr are unsigned operations, so cut off upper bits }
|
||||||
|
case resultdef.size of
|
||||||
|
1:
|
||||||
|
rvalue:=tordconstnode(right).value and byte($7);
|
||||||
|
2:
|
||||||
|
rvalue:=tordconstnode(right).value and byte($f);
|
||||||
|
4:
|
||||||
|
rvalue:=tordconstnode(right).value and byte($1f);
|
||||||
|
8:
|
||||||
|
rvalue:=tordconstnode(right).value and byte($3f);
|
||||||
|
else
|
||||||
|
internalerror(2013122302);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
rvalue:=tordconstnode(right).value;
|
||||||
|
if is_constintnode(left) then
|
||||||
begin
|
begin
|
||||||
{ shl/shr are unsigned operations, so cut off upper bits }
|
if forinline then
|
||||||
case resultdef.size of
|
begin
|
||||||
1:
|
{ shl/shr are unsigned operations, so cut off upper bits }
|
||||||
begin
|
case resultdef.size of
|
||||||
rvalue:=tordconstnode(right).value and byte($7);
|
1:
|
||||||
lvalue:=tordconstnode(left).value and byte($ff);
|
lvalue:=tordconstnode(left).value and byte($ff);
|
||||||
|
2:
|
||||||
|
lvalue:=tordconstnode(left).value and word($ffff);
|
||||||
|
4:
|
||||||
|
lvalue:=tordconstnode(left).value and dword($ffffffff);
|
||||||
|
8:
|
||||||
|
lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
|
||||||
|
else
|
||||||
|
internalerror(2013122301);
|
||||||
end;
|
end;
|
||||||
2:
|
end
|
||||||
begin
|
else
|
||||||
rvalue:=tordconstnode(right).value and byte($f);
|
lvalue:=tordconstnode(left).value;
|
||||||
lvalue:=tordconstnode(left).value and word($ffff);
|
case nodetype of
|
||||||
end;
|
shrn:
|
||||||
4:
|
result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline);
|
||||||
begin
|
shln:
|
||||||
rvalue:=tordconstnode(right).value and byte($1f);
|
result:=create_simplified_ord_const(lvalue shl rvalue,resultdef,forinline);
|
||||||
lvalue:=tordconstnode(left).value and dword($ffffffff);
|
|
||||||
end;
|
|
||||||
8:
|
|
||||||
begin
|
|
||||||
rvalue:=tordconstnode(right).value and byte($3f);
|
|
||||||
lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
|
|
||||||
end;
|
|
||||||
else
|
|
||||||
internalerror(2013122301);
|
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else
|
else if rvalue=0 then
|
||||||
begin
|
begin
|
||||||
rvalue:=tordconstnode(right).value;
|
result:=left;
|
||||||
lvalue:=tordconstnode(left).value;
|
left:=nil;
|
||||||
end;
|
end;
|
||||||
case nodetype of
|
|
||||||
shrn:
|
|
||||||
result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline);
|
|
||||||
shln:
|
|
||||||
result:=create_simplified_ord_const(lvalue shl rvalue,resultdef,forinline);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user