mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-30 20:20:47 +02:00
+ optimize '0 shl x' and '0 shr x' to 0
git-svn-id: trunk@36041 -
This commit is contained in:
parent
546e993c25
commit
de1e0c405e
@ -702,6 +702,28 @@ implementation
|
||||
result:=left;
|
||||
left:=nil;
|
||||
end;
|
||||
end
|
||||
else if is_constintnode(left) then
|
||||
begin
|
||||
lvalue:=tordconstnode(left).value;
|
||||
{ shl/shr are unsigned operations, so cut off upper bits }
|
||||
case resultdef.size of
|
||||
1:
|
||||
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;
|
||||
{ '0 shl x' and '0 shr x' are 0 }
|
||||
if (lvalue=0) and
|
||||
((cs_opt_level4 in current_settings.optimizerswitches) or
|
||||
not might_have_sideeffects(right)) then
|
||||
result:=cordconstnode.create(0,resultdef,true);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user