From e796a878ca05e2612755c877d48dfa1af341cff9 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 17 Aug 2011 16:00:16 +0000 Subject: [PATCH] * convert * into sqr(), it might reduces register pressure and/or memory accesses without a drawback git-svn-id: trunk@18252 - --- compiler/nadd.pas | 69 ++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 8a0477f6fd..43e288c06c 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -748,35 +748,48 @@ implementation exit; end; - { the comparison is might be expensive and the nodes are usually only - equal if some previous optimizations were done so don't check - this simplification always - } - if (cs_opt_level2 in current_settings.optimizerswitches) and - is_boolean(left.resultdef) and is_boolean(right.resultdef) and - { since the expressions might have sideeffects, we may only remove them - if short boolean evaluation is turned on } - (nf_short_bool in flags) then - begin - if left.isequal(right) then - begin - case nodetype of - andn,orn: - begin - result:=left; - left:=nil; - exit; - end; - { - xorn: - begin - result:=cordconstnode.create(0,resultdef,true); - exit; - end; - } + { slow simplifications } + if (cs_opt_level2 in current_settings.optimizerswitches) then + begin + { the comparison is might be expensive and the nodes are usually only + equal if some previous optimizations were done so don't check + this simplification always + } + if is_boolean(left.resultdef) and is_boolean(right.resultdef) and + { since the expressions might have sideeffects, we may only remove them + if short boolean evaluation is turned on } + (nf_short_bool in flags) then + begin + if left.isequal(right) then + begin + case nodetype of + andn,orn: + begin + result:=left; + left:=nil; + exit; + end; + { + xorn: + begin + result:=cordconstnode.create(0,resultdef,true); + exit; + end; + } + end; end; - end; - end; + end; + + { using sqr(x) for reals instead of x*x might reduces register pressure and/or + memory accesses while sqr() has no drawback } + if is_real(left.resultdef) and is_real(left.resultdef) and + left.isequal(right) then + begin + result:=cinlinenode.create(in_sqr_real,false,left); + left:=nil; + exit; + end; + end; end;