summaryrefslogtreecommitdiff
path: root/compiler/nadd.pas
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-01-01 15:26:13 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-01-01 15:26:13 +0000
commit1b37334d22653550322b57e5a85d9b1b97f1d283 (patch)
tree5e5aed5b189bfa7444ffd9a48ccf5092598b644a /compiler/nadd.pas
parent3a65274c64b04ac917b1370ce0a5ae11f0630005 (diff)
downloadfpc-1b37334d22653550322b57e5a85d9b1b97f1d283.tar.gz
* first part of fixing #38267: do not bail out early during constant folding
if the constant is 1 or -1 git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@47933 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'compiler/nadd.pas')
-rw-r--r--compiler/nadd.pas29
1 files changed, 9 insertions, 20 deletions
diff --git a/compiler/nadd.pas b/compiler/nadd.pas
index 83b82fde05..07dabeb40f 100644
--- a/compiler/nadd.pas
+++ b/compiler/nadd.pas
@@ -708,9 +708,9 @@ implementation
end;
{ Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1? }
- if is_constintnode(right) and (is_integer(left.resultdef) or is_pointer(left.resultdef)) then
+ if is_constintnode(right) and (is_integer(left.resultdef) or is_pointer(left.resultdef)) then
begin
- if tordconstnode(right).value = 0 then
+ if (tordconstnode(right).value = 0) and (nodetype in [addn,subn,orn,xorn,andn,muln]) then
begin
case nodetype of
addn,subn,orn,xorn:
@@ -725,24 +725,13 @@ implementation
;
end;
end
- else if tordconstnode(right).value = 1 then
- begin
- case nodetype of
- muln:
- result := left.getcopy;
- else
- ;
- end;
- end
- else if tordconstnode(right).value = -1 then
- begin
- case nodetype of
- muln:
- result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef);
- else
- ;
- end;
- end
+
+ else if (tordconstnode(right).value = 1) and (nodetype=muln) then
+ result := left.getcopy
+
+ else if (tordconstnode(right).value = -1) and (nodetype=muln) then
+ result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef)
+
{ try to fold
op op
/ \ / \