mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 03:09:36 +02:00
+ perform the "i:=-i" / "i:=not i" optimization even when there are typecasts
inserted; this makes the optimization work for all integer types git-svn-id: trunk@35763 -
This commit is contained in:
parent
98be270adb
commit
d8406c4227
@ -670,9 +670,8 @@ implementation
|
|||||||
end;
|
end;
|
||||||
{ replace i:=not i by in_not_assign_x(i)
|
{ replace i:=not i by in_not_assign_x(i)
|
||||||
i:=-i by in_neg_assign_x(i)
|
i:=-i by in_neg_assign_x(i)
|
||||||
todo: for some integer types, there are extra implicit
|
|
||||||
typecasts inserted by the compiler; this code should be
|
this handles the case, where there are no implicit type conversions }
|
||||||
updated to handle them as well }
|
|
||||||
if (right.nodetype in [notn,unaryminusn]) and
|
if (right.nodetype in [notn,unaryminusn]) and
|
||||||
(tunarynode(right).left.isequal(left)) and
|
(tunarynode(right).left.isequal(left)) and
|
||||||
is_integer(tunarynode(right).left.resultdef) and
|
is_integer(tunarynode(right).left.resultdef) and
|
||||||
@ -690,6 +689,38 @@ implementation
|
|||||||
left:=nil;
|
left:=nil;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
{ replace i:=not i by in_not_assign_x(i)
|
||||||
|
i:=-i by in_neg_assign_x(i)
|
||||||
|
|
||||||
|
this handles the case with type conversions:
|
||||||
|
outer typeconv: right
|
||||||
|
neg/not: ttypeconvnode(right).left
|
||||||
|
inner typeconv: tunarynode(ttypeconvnode(right).left).left
|
||||||
|
right side 'i': ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).left }
|
||||||
|
if (right.nodetype=typeconvn) and
|
||||||
|
(ttypeconvnode(right).convtype=tc_int_2_int) and
|
||||||
|
(ttypeconvnode(right).left.nodetype in [notn,unaryminusn]) and
|
||||||
|
is_integer(ttypeconvnode(right).left.resultdef) and
|
||||||
|
(right.resultdef.size<=ttypeconvnode(right).left.resultdef.size) and
|
||||||
|
(tunarynode(ttypeconvnode(right).left).left.nodetype=typeconvn) and
|
||||||
|
(ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).convtype=tc_int_2_int) and
|
||||||
|
are_equal_ints(right.resultdef,ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).left.resultdef) and
|
||||||
|
ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).left.isequal(left) and
|
||||||
|
is_integer(ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).left.resultdef) and
|
||||||
|
((localswitches*[cs_check_overflow,cs_check_range])=[]) and
|
||||||
|
((right.localswitches*[cs_check_overflow,cs_check_range])=[]) and
|
||||||
|
valid_for_var(ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).left,false) and
|
||||||
|
not(might_have_sideeffects(ttypeconvnode(tunarynode(ttypeconvnode(right).left).left).left)) then
|
||||||
|
begin
|
||||||
|
if ttypeconvnode(right).left.nodetype=notn then
|
||||||
|
newinlinenodetype:=in_not_assign_x
|
||||||
|
else
|
||||||
|
newinlinenodetype:=in_neg_assign_x;
|
||||||
|
result:=cinlinenode.createintern(
|
||||||
|
newinlinenodetype,false,left);
|
||||||
|
left:=nil;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user