From a58e07df38ca8f5f1ebb9a9c3ac3c2ecf7908a06 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 17 Jan 2010 14:39:58 +0000 Subject: [PATCH] * optimize and/or if they are equal and boolean git-svn-id: trunk@14714 - --- compiler/nadd.pas | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/compiler/nadd.pas b/compiler/nadd.pas index a255a35820..d602510b09 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -744,6 +744,35 @@ 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; + } + end; + end; + end; end;