Browse Source

* when optimizing boolean expressions, might_have_sideeffects is only relevant if the expression would be optimized away

git-svn-id: trunk@44084 -
florian 5 years ago
parent
commit
77b54f501f
1 changed files with 8 additions and 6 deletions
  1. 8 6
      compiler/nadd.pas

+ 8 - 6
compiler/nadd.pas

@@ -1148,7 +1148,7 @@ implementation
           containing constants }
         if is_boolean(left.resultdef) and is_boolean(right.resultdef) then
           begin
-            if is_constboolnode(left) and not(might_have_sideeffects(right)) then
+            if is_constboolnode(left) then
               begin
                 if ((nodetype=andn) and (tordconstnode(left).value<>0)) or
                   ((nodetype=orn) and (tordconstnode(left).value=0)) or
@@ -1158,8 +1158,9 @@ implementation
                     right:=nil;
                     exit;
                   end
-                else if ((nodetype=orn) and (tordconstnode(left).value<>0)) or
-                  ((nodetype=andn) and (tordconstnode(left).value=0)) then
+                else if not(might_have_sideeffects(right)) and
+                  (((nodetype=orn) and (tordconstnode(left).value<>0)) or
+                  ((nodetype=andn) and (tordconstnode(left).value=0))) then
                   begin
                     result:=left;
                     left:=nil;
@@ -1172,7 +1173,7 @@ implementation
                     exit;
                   end
               end
-            else if is_constboolnode(right) and not(might_have_sideeffects(left)) then
+            else if is_constboolnode(right) then
               begin
                 if ((nodetype=andn) and (tordconstnode(right).value<>0)) or
                   ((nodetype=orn) and (tordconstnode(right).value=0)) or
@@ -1182,8 +1183,9 @@ implementation
                     left:=nil;
                     exit;
                   end
-                else if ((nodetype=orn) and (tordconstnode(right).value<>0)) or
-                  ((nodetype=andn) and (tordconstnode(right).value=0)) then
+                else if not(might_have_sideeffects(left)) and
+                  (((nodetype=orn) and (tordconstnode(right).value<>0)) or
+                   ((nodetype=andn) and (tordconstnode(right).value=0))) then
                   begin
                     result:=right;
                     right:=nil;