]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
Convert constant conditional branches such as "if true goto L" into
authorRhys Weatherley <rweather@southern-storm.com.au>
Thu, 20 May 2004 01:24:54 +0000 (01:24 +0000)
committerRhys Weatherley <rweather@southern-storm.com.au>
Thu, 20 May 2004 01:24:54 +0000 (01:24 +0000)
unconditional branches.

ChangeLog
include/jit/jit-value.h
jit/jit-insn.c
jit/jit-value.c

index 80886d8c1c60436c370cec49da7b70c66697593c..9d3e55d5ad4d18400ab6e7f68e7c5e55040109fc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
 
+2004-05-20  Rhys Weatherley  <rweather@southern-storm.com.au>
+
+       * include/jit/jit-value.h, jit/jit-insn.c, jit/jit-value.c:
+       convert constant conditional branches such as "if true goto L" into
+       unconditional branches.
+
 2004-05-15  Rhys Weatherley  <rweather@southern-storm.com.au>
 
        * tools/gen-apply.c: fix a macro generation bug for Win32 systems.
index c72f0f2c2ab966503cfa8ff4edacc64c7b0605aa..81e7c560e3321d37cc1de2737f8a214f338407d0 100644 (file)
@@ -90,6 +90,7 @@ jit_long jit_value_get_long_constant(jit_value_t value) JIT_NOTHROW;
 jit_float32 jit_value_get_float32_constant(jit_value_t value) JIT_NOTHROW;
 jit_float64 jit_value_get_float64_constant(jit_value_t value) JIT_NOTHROW;
 jit_nfloat jit_value_get_nfloat_constant(jit_value_t value) JIT_NOTHROW;
+int jit_value_is_true(jit_value_t value) JIT_NOTHROW;
 int jit_constant_convert
        (jit_constant_t *result, const jit_constant_t *value,
         jit_type_t type, int overflow_check) JIT_NOTHROW;
index 9d0b590130530189caaa628fea7501edcb64f363..30933463ff62f7ed93830ad60db457eae1ba12c4 100644 (file)
@@ -3547,6 +3547,20 @@ int jit_insn_branch_if
                *label = (func->builder->next_label)++;
        }
 
+       /* If the condition is constant, then convert it into either
+          an unconditional branch or a fall-through, as appropriate */
+       if(jit_value_is_constant(value))
+       {
+               if(jit_value_is_true(value))
+               {
+                       return jit_insn_branch(func, label);
+               }
+               else
+               {
+                       return 1;
+               }
+       }
+
        /* Determine if we can replace a previous comparison instruction */
        block = func->builder->current_block;
        insn = _jit_block_get_last(block);
@@ -3734,6 +3748,20 @@ int jit_insn_branch_if_not
                *label = (func->builder->next_label)++;
        }
 
+       /* If the condition is constant, then convert it into either
+          an unconditional branch or a fall-through, as appropriate */
+       if(jit_value_is_constant(value))
+       {
+               if(!jit_value_is_true(value))
+               {
+                       return jit_insn_branch(func, label);
+               }
+               else
+               {
+                       return 1;
+               }
+       }
+
        /* Determine if we can replace a previous comparison instruction */
        block = func->builder->current_block;
        insn = _jit_block_get_last(block);
index db018f16b3d0ba51449240c618861d9d79ef5c83..7f0db7c4095780c857df08217be0c85b42f18071 100644 (file)
@@ -929,6 +929,66 @@ jit_nfloat jit_value_get_nfloat_constant(jit_value_t value)
        return (jit_nfloat)0.0;
 }
 
+/*@
+ * @deftypefun int jit_value_is_true (jit_value_t value)
+ * Determine if @code{value} is constant and non-zero.
+ * @end deftypefun
+@*/
+int jit_value_is_true(jit_value_t value)
+{
+       if(!value || !(value->is_constant))
+       {
+               return 0;
+       }
+       else if(value->is_nint_constant)
+       {
+               return (value->address != 0);
+       }
+       else
+       {
+               switch(jit_type_normalize(value->type)->kind)
+               {
+                       case JIT_TYPE_LONG:
+                       case JIT_TYPE_ULONG:
+                       {
+                               if(jit_value_get_long_constant(value) != 0)
+                               {
+                                       return 1;
+                               }
+                       }
+                       break;
+
+                       case JIT_TYPE_FLOAT32:
+                       {
+                               if(jit_value_get_float32_constant(value) != (jit_float32)0.0)
+                               {
+                                       return 1;
+                               }
+                       }
+                       break;
+
+                       case JIT_TYPE_FLOAT64:
+                       {
+                               if(jit_value_get_float64_constant(value) != (jit_float64)0.0)
+                               {
+                                       return 1;
+                               }
+                       }
+                       break;
+
+                       case JIT_TYPE_NFLOAT:
+                       {
+                               if(jit_value_get_nfloat_constant(value) != (jit_nfloat)0.0)
+                               {
+                                       return 1;
+                               }
+                       }
+                       break;
+               }
+               return 0;
+       }
+}
+
 /*@
  * @deftypefun int jit_constant_convert ({jit_constant_t *} result, {const jit_constant_t *} value, jit_type_t type, int overflow_check)
  * Convert a the constant @code{value} into a new @code{type}, and