Tue Jun 5 17:40:04 CEST 2007 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 5 Jun 2007 15:42:10 +0000 (15:42 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 5 Jun 2007 15:42:10 +0000 (15:42 -0000)
* mini.c: optimizee out the type check when storing null in a
reference array.

svn path=/trunk/mono/; revision=78640

mono/mini/ChangeLog
mono/mini/mini.c

index 3c75edcbbec21e2048e43a07c46b60ca29ad7358..bdc3ba834dd827138c6b1080fbd2a99b14b1cd83 100644 (file)
@@ -1,3 +1,9 @@
+
+Tue Jun 5 17:40:04 CEST 2007 Paolo Molaro <lupus@ximian.com>
+
+       * mini.c: optimizee out the type check when storing null in a
+       reference array.
+
 2007-06-04  Mark Probst  <mark.probst@gmail.com>
 
        * mini.c, driver.c: Changed MonoDomain.jit_code_hash to a
index 8825317742f0c50e0a893434fb6e9cd819959784..18a69edbce30ca3a7d2b7a3abfaca7675d005950 100644 (file)
@@ -6730,15 +6730,27 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                        CHECK_TYPELOAD (klass);
                        mono_class_init (klass);
                        if (MONO_TYPE_IS_REFERENCE (&klass->byval_arg)) {
-                               MonoMethod* helper = mono_marshal_get_stelemref ();
-                               MonoInst *iargs [3];
-                               handle_loaded_temps (cfg, bblock, stack_start, sp);
+                               /* storing a NULL doesn't need any of the complex checks in stelemref */
+                               if (sp [2]->opcode == OP_PCONST && sp [2]->inst_p0 == NULL) {
+                                       MonoInst *load;
+                                       NEW_LDELEMA (cfg, load, sp, mono_defaults.object_class);
+                                       load->cil_code = ip;
+                                       MONO_INST_NEW (cfg, ins, stelem_to_stind [*ip - CEE_STELEM_I]);
+                                       ins->cil_code = ip;
+                                       ins->inst_left = load;
+                                       ins->inst_right = sp [2];
+                                       MONO_ADD_INS (bblock, ins);
+                               } else {
+                                       MonoMethod* helper = mono_marshal_get_stelemref ();
+                                       MonoInst *iargs [3];
+                                       handle_loaded_temps (cfg, bblock, stack_start, sp);
 
-                               iargs [2] = sp [2];
-                               iargs [1] = sp [1];
-                               iargs [0] = sp [0];
-                               
-                               mono_emit_method_call_spilled (cfg, bblock, helper, mono_method_signature (helper), iargs, ip, NULL);
+                                       iargs [2] = sp [2];
+                                       iargs [1] = sp [1];
+                                       iargs [0] = sp [0];
+
+                                       mono_emit_method_call_spilled (cfg, bblock, helper, mono_method_signature (helper), iargs, ip, NULL);
+                               }
                        } else {
                                NEW_LDELEMA (cfg, load, sp, klass);
                                load->cil_code = ip;
@@ -6772,24 +6784,26 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
 
                        handle_loaded_temps (cfg, bblock, stack_start, sp);
 
-                       iargs [2] = sp [2];
-                       iargs [1] = sp [1];
-                       iargs [0] = sp [0];
+                       /* storing a NULL doesn't need any of the complex checks in stelemref */
+                       if (sp [2]->opcode == OP_PCONST && sp [2]->inst_p0 == NULL) {
+                               MonoInst *load;
+                               NEW_LDELEMA (cfg, load, sp, mono_defaults.object_class);
+                               load->cil_code = ip;
+                               MONO_INST_NEW (cfg, ins, stelem_to_stind [*ip - CEE_STELEM_I]);
+                               ins->cil_code = ip;
+                               ins->inst_left = load;
+                               ins->inst_right = sp [2];
+                               MONO_ADD_INS (bblock, ins);
+                       } else {
+                               iargs [2] = sp [2];
+                               iargs [1] = sp [1];
+                               iargs [0] = sp [0];
                        
-                       mono_emit_method_call_spilled (cfg, bblock, helper, mono_method_signature (helper), iargs, ip, NULL);
-
-                       /*
-                       MonoInst *group;
-                       NEW_GROUP (cfg, group, sp [0], sp [1]);
-                       MONO_INST_NEW (cfg, ins, CEE_STELEM_REF);
-                       ins->cil_code = ip;
-                       ins->inst_left = group;
-                       ins->inst_right = sp [2];
-                       MONO_ADD_INS (bblock, ins);
-                       */
+                               mono_emit_method_call_spilled (cfg, bblock, helper, mono_method_signature (helper), iargs, ip, NULL);
+                               inline_costs += 1;
+                       }
 
                        ++ip;
-                       inline_costs += 1;
                        break;
                }
                case CEE_CKFINITE: {