* keep type when removing "1*", resolves #38840

This commit is contained in:
florian 2021-10-17 21:57:39 +02:00
parent e97e27b8d5
commit 08050086b9
2 changed files with 24 additions and 2 deletions

View File

@ -827,7 +827,10 @@ implementation
end
else if (tordconstnode(right).value = 1) and (nodetype=muln) then
result := left.getcopy
{ insert type conversion in case it is a 32*32 to 64 bit multiplication optimization,
the type conversion does not hurt because it is normally removed later on
}
result := ctypeconvnode.create_internal(left.getcopy,resultdef)
else if (tordconstnode(right).value = -1) and (nodetype=muln) then
result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef)
@ -895,7 +898,10 @@ implementation
end
else if (tordconstnode(left).value = 1) and (nodetype=muln) then
result := right.getcopy
{ insert type conversion in case it is a 32*32 to 64 bit multiplication optimization,
the type conversion does not hurt because it is normally removed later on
}
result := ctypeconvnode.create_internal(right.getcopy,resultdef)
else if (tordconstnode(left).value = -1) and (nodetype=muln) then
result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef)

16
tests/webtbs/tw38840.pp Normal file
View File

@ -0,0 +1,16 @@
{ %opt=-O4 -CriotR }
{$mode objfpc}
function f : integer;
begin
result:=1234;
end;
var r, s, t, tablecols : integer;
begin
s := 1;
t := r + (s*tablecols);
t := r + (s*tablecols);
end.