Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / mini / cfold.c
index d9e35d4702ed2ccd72b686482737bd05be03f6d3..940c07ac8d825b9d0bb3886ec37d35b71319ef41 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * cfold.c: Constant folding support
+/**
+ * \file
+ * Constant folding support
  *
  * Author:
  *   Paolo Molaro (lupus@ximian.com)
@@ -7,9 +8,12 @@
  *
  * (C) 2003 Ximian, Inc.  http://www.ximian.com
  */
+#include <config.h>
+
 #include "mini.h"
 #include "ir-emit.h"
 
+/* WTF is this doing here?!?!? */
 int
 mono_is_power_of_two (guint32 val)
 {
@@ -66,6 +70,8 @@ mono_is_power_of_two (guint32 val)
     } \
 } while (0)
 
+#ifndef DISABLE_JIT
+
 /**
  * mono_constant_fold_ins:
  *
@@ -330,6 +336,19 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns
                                        dest->inst_c0 = res;
                                }
                                break;
+                       case OP_COND_EXC_EQ:
+                               res = arg1->inst_c0 == arg2->inst_c0;
+                               if (!res) {
+                                       if (overwrite) {
+                                               NULLIFY_INS (ins);
+                                               NULLIFY_INS (next);
+                                       } else {
+                                               ALLOC_DEST (cfg, dest, ins);
+                                               dest->opcode = OP_ICONST;
+                                               dest->inst_c0 = res;
+                                       }
+                               }
+                               break;
                        case OP_NOP:
                        case OP_BR:
                                /* This happens when a conditional branch is eliminated */
@@ -343,6 +362,24 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns
                                return NULL;
                        }
                }
+               if ((arg1->opcode == OP_PCONST) && (arg2->opcode == OP_PCONST) && ins->next) {
+                       MonoInst *next = ins->next;
+
+                       if (next->opcode == OP_LCEQ) {
+                               gboolean res = arg1->inst_p0 == arg2->inst_p0;
+                               if (overwrite) {
+                                       NULLIFY_INS (ins);
+                                       next->opcode = OP_ICONST;
+                                       next->inst_c0 = res;
+                                       MONO_INST_NULLIFY_SREGS (next);
+                               } else {
+                                       ALLOC_DEST (cfg, dest, ins);
+                                       dest->opcode = OP_ICONST;
+                                       dest->inst_c0 = res;
+                               }
+                               break;
+                       }
+               }
                break;
        }
        case OP_FMOVE:
@@ -366,3 +403,6 @@ mono_constant_fold_ins (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoIns
                
     return dest;
 }      
+
+
+#endif /* DISABLE_JIT */