Browse Source

+ optimization in thlcgwasm.a_load_reg_reg: don't emit any instructions when moving the same size from a register to itself

Nikolay Nikolov 23 hours ago
parent
commit
4ad6636f05
1 changed files with 9 additions and 0 deletions
  1. 9 0
      compiler/wasm32/hlcgcpu.pas

+ 9 - 0
compiler/wasm32/hlcgcpu.pas

@@ -1435,7 +1435,16 @@ implementation
     end;
 
   procedure thlcgwasm.a_load_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister);
+    var
+      fromcgsize, tocgsize: TCgSize;
     begin
+      fromcgsize:=def_cgsize(fromsize);
+      tocgsize:=def_cgsize(tosize);
+      if (reg1=reg2) and ((fromcgsize=tocgsize) or
+                          ((fromcgsize in [OS_S32,OS_32]) and (tocgsize in [OS_S32,OS_32]) and (getsubreg(reg1)=R_SUBD)) or
+                          ((fromcgsize in [OS_S64,OS_64]) and (tocgsize in [OS_S64,OS_64]))) then
+        exit;
+
       a_load_reg_stack(list,fromsize,reg1);
       if def2regtyp(fromsize) in [R_INTREGISTER,R_ADDRESSREGISTER] then
         resize_stack_int_val(list,fromsize,tosize,false);