Ver código fonte

* extend node_not_zero and make more use of it

florian 5 meses atrás
pai
commit
bcaa58db01
2 arquivos alterados com 10 adições e 6 exclusões
  1. 9 6
      compiler/aarch64/ncpumat.pas
  2. 1 0
      compiler/nutils.pas

+ 9 - 6
compiler/aarch64/ncpumat.pas

@@ -52,7 +52,7 @@ implementation
       aasmbase,aasmcpu,aasmtai,aasmdata,
       defutil,
       cgbase,cgobj,hlcgobj,pass_2,procinfo,
-      ncon,
+      ncon,nutils,
       cpubase,
       ncgutil,cgcpu,cgutils;
 
@@ -420,11 +420,14 @@ implementation
 
             current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,resultreg,numerator,divider));
 
-            current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,divider,0));
-            current_asmdata.getjumplabel(hl);
-            current_asmdata.CurrAsmList.concat(taicpu.op_cond_sym(A_B,C_NE,hl));
-            cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DIVBYZERO',false);
-            cg.a_label(current_asmdata.CurrAsmList,hl);
+            if not(node_not_zero(right)) then
+              begin
+                current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,divider,0));
+                current_asmdata.getjumplabel(hl);
+                current_asmdata.CurrAsmList.concat(taicpu.op_cond_sym(A_B,C_NE,hl));
+                cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DIVBYZERO',false);
+                cg.a_label(current_asmdata.CurrAsmList,hl);
+              end;
           end;
 
         genOverflowCheck;

+ 1 - 0
compiler/nutils.pas

@@ -1734,6 +1734,7 @@ implementation
      function node_not_zero(n: tnode): Boolean;
        begin
          result:=(is_constintnode(n) and (get_int_value(n)<>0)) or
+           ((n.nodetype=typeconvn) and (ttypeconvnode(n).convtype=tc_int_2_int) and node_not_zero(ttypeconvnode(n).left)) or
            ((n.nodetype=orn) and (node_not_zero(taddnode(n).left) or node_not_zero(taddnode(n).right)));
        end;