浏览代码

* avoid some unnecessary bool->int->bool type conversions

git-svn-id: trunk@3184 -
Jonas Maebe 19 年之前
父节点
当前提交
039e7143f4
共有 3 个文件被更改,包括 22 次插入9 次删除
  1. 2 2
      compiler/nadd.pas
  2. 12 4
      compiler/ncgcnv.pas
  3. 8 3
      compiler/ncnv.pas

+ 2 - 2
compiler/nadd.pas

@@ -818,13 +818,13 @@ implementation
                 if torddef(left.resulttype.def).size>torddef(right.resulttype.def).size then
                 if torddef(left.resulttype.def).size>torddef(right.resulttype.def).size then
                  begin
                  begin
                    right:=ctypeconvnode.create_internal(right,left.resulttype);
                    right:=ctypeconvnode.create_internal(right,left.resulttype);
-                   ttypeconvnode(right).convtype:=tc_bool_2_int;
+                   ttypeconvnode(right).convtype:=tc_bool_2_bool;
                    resulttypepass(right);
                    resulttypepass(right);
                  end
                  end
                 else if torddef(left.resulttype.def).size<torddef(right.resulttype.def).size then
                 else if torddef(left.resulttype.def).size<torddef(right.resulttype.def).size then
                  begin
                  begin
                    left:=ctypeconvnode.create_internal(left,right.resulttype);
                    left:=ctypeconvnode.create_internal(left,right.resulttype);
-                   ttypeconvnode(left).convtype:=tc_bool_2_int;
+                   ttypeconvnode(left).convtype:=tc_bool_2_bool;
                    resulttypepass(left);
                    resulttypepass(left);
                  end;
                  end;
                 case nodetype of
                 case nodetype of

+ 12 - 4
compiler/ncgcnv.pas

@@ -392,10 +392,18 @@ interface
           the bits that define the true status can be outside the limits
           the bits that define the true status can be outside the limits
           of the new size and truncating the register can result in a 0
           of the new size and truncating the register can result in a 0
           value }
           value }
-        if resulttype.def.size<left.resulttype.def.size then
-          second_int_to_bool
-        else
-          second_bool_to_int;
+        if (left.expectloc in [LOC_FLAGS,LOC_JUMP]) then
+          begin
+            secondpass(left);
+            if (left.location.loc <> left.expectloc) then
+              internalerror(20060409);
+            location_copy(location,left.location);
+          end
+         else
+           if resulttype.def.size<left.resulttype.def.size then
+             second_int_to_bool
+           else
+             second_bool_to_int;
       end;
       end;
 
 
 
 

+ 8 - 3
compiler/ncnv.pas

@@ -2023,9 +2023,14 @@ implementation
     function ttypeconvnode.first_bool_to_bool : tnode;
     function ttypeconvnode.first_bool_to_bool : tnode;
       begin
       begin
          first_bool_to_bool:=nil;
          first_bool_to_bool:=nil;
-         expectloc:=LOC_REGISTER;
-         if registersint<1 then
-           registersint:=1;
+         if (left.expectloc in [LOC_FLAGS,LOC_JUMP]) then
+           expectloc := left.expectloc
+         else
+           begin
+             expectloc:=LOC_REGISTER;
+             if registersint<1 then
+               registersint:=1;
+           end;
       end;
       end;