BugFix: TLS variables are Sels, not SymConst
[libfirm] / ir / ana / irmemory.c
index 94891ff..8020bae 100644 (file)
@@ -34,7 +34,7 @@ static unsigned global_mem_disamgig_opt = aa_opt_no_opt;
 
 /* Get the memory disambiguator options for a graph. */
 unsigned get_irg_memory_disambiguator_options(ir_graph *irg) {
-       unsigned opt = irg->mem_disamgig_opt;
+       unsigned opt = irg->mem_disambig_opt;
        if (opt & aa_opt_inherited)
                return global_mem_disamgig_opt;
        return opt;
@@ -42,7 +42,7 @@ unsigned get_irg_memory_disambiguator_options(ir_graph *irg) {
 
 /*  Set the memory disambiguator options for a graph. */
 void set_irg_memory_disambiguator_options(ir_graph *irg, unsigned options) {
-       irg->mem_disamgig_opt = options & ~aa_opt_inherited;
+       irg->mem_disambig_opt = options & ~aa_opt_inherited;
 }  /* set_irg_memory_disambiguator_options */
 
 /* Set the global disambiguator options for all graphs not having local options. */
@@ -132,6 +132,20 @@ static ir_alias_relation different_types(ir_node *adr1, ir_node *adr2)
        return may_alias;
 }  /* different_types */
 
+/**
+ * Returns non-zero if a node is a routine parameter.
+ *
+ * @param node  the node to test
+ */
+static int is_arg_Proj(ir_node *node) {
+       if (! is_Proj(node))
+               return 0;
+       node = get_Proj_pred(node);
+       if (! is_Proj(node))
+               return 0;
+       return pn_Start_T_args == get_Proj_proj(node) && is_Start(get_Proj_pred(node));
+}  /* is_arg_Proj */
+
 /**
  * Determine the alias relation between two addresses.
  */
@@ -140,7 +154,7 @@ static ir_alias_relation _get_alias_relation(
        ir_node *adr1, ir_mode *mode1,
        ir_node *adr2, ir_mode *mode2)
 {
-       opcode op1, op2;
+       ir_opcode op1, op2;
        ir_entity *ent1, *ent2;
        unsigned options;
 
@@ -158,7 +172,7 @@ static ir_alias_relation _get_alias_relation(
 
        /* Two save some code, sort the addresses by its id's. Beware, this
           might break some things, so better check here. */
-       assert(iro_SymConst < iro_Sel && "Code dependence breaked");
+       assert(iro_SymConst < iro_Sel && iro_Sel < iro_Proj && "Code dependence breaked");
        op1 = get_irn_opcode(adr1);
        op2 = get_irn_opcode(adr2);
 
@@ -232,7 +246,14 @@ static ir_alias_relation _get_alias_relation(
                                        /* the second one is a TLS variable so they are always
                                       different (R1 d) */
                                        return no_alias;
+                               } else if (is_arg_Proj(base2)) {
+                                       /* the second one is an offset from a parameter so they are
+                                          always different (R1 e) */
+                                       return no_alias;
                                }
+                       } else if (is_arg_Proj(adr2)) {
+                               /* a local variable and a parameter are always different (R1 e) */
+                               return no_alias;
                        }
                } else if (base1 == get_irg_tls(irg)) {
                        /* the first is a TLS variable */
@@ -253,16 +274,29 @@ static ir_alias_relation _get_alias_relation(
                                                return different_offsets(adr1, adr2);
                                }
                        }
+               } else if (is_arg_Proj(base1)) {
+                       /* the first one is an offset from a parameter */
+                       if (is_Sel(adr2)) {
+                               /* the second address is a Sel */
+                               ir_node *base2 = find_base_adr(adr2, &ent2);
+
+                               if (base2 == get_irg_frame(irg)) {
+                                       /* the second one is a local variable so they are always
+                                      different (R1 e) */
+                                       return no_alias;
+                               }
+                       }
                }
        }
 
-       if (options & aa_opt_type_based) {
+       if (options & aa_opt_type_based) { /* Type based alias analysis */
                ir_alias_relation rel;
 
                if (options & aa_opt_byte_type_may_alias) {
                        if (get_mode_size_bits(mode1) == 8 || get_mode_size_bits(mode2) == 8) {
-                               /* One of the modes address a byte. Assume a may_alias. */
-                               return may_alias;
+                               /* One of the modes address a byte. Assume a may_alias and leave
+                                  the type based check. */
+                               goto leave_type_based_alias;
                        }
                }
                /* cheap check: If the mode sizes did not match, the types MUST be different */
@@ -273,6 +307,7 @@ static ir_alias_relation _get_alias_relation(
                rel = different_types(adr1, adr2);
                if (rel != may_alias)
                        return rel;
+leave_type_based_alias:;
        }
 
        /* do we have a language specific memory disambiguator? */
@@ -562,7 +597,7 @@ static void check_global_address(ir_node *irn, void *env) {
                ent = get_SymConst_entity(irn);
        } else if (is_Sel(irn) && get_Sel_ptr(irn) == tls) {
                /* A TLS variable. */
-               ent = get_SymConst_entity(irn);
+               ent = get_Sel_entity(irn);
        } else
                return;