소스 검색

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

git-svn-id: trunk@44084 -
florian 5 년 전
부모
커밋
77b54f501f
1개의 변경된 파일8개의 추가작업 그리고 6개의 파일을 삭제
  1. 8 6
      compiler/nadd.pas

+ 8 - 6
compiler/nadd.pas

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