On 07/14/11 18:29, Richard Henderson wrote:
> On 07/14/2011 09:23 AM, Bernd Schmidt wrote:
>> Ok, with gen_const_mem hacked into gcc-3.3 (minus setting MEM_READONLY_P
>> which doesn't exist in that tree) the load stays behind the branch where
>> it should be.
>>
> 
> RTX_UNCHANGING_P was the bit back then, I believe.

Still ok with that also set:
        addl r14 = @ltoff(ap_standalone#), r1
        ;;
        .mii
        ld8 r15 = [r14]
        addl r14 = @ltoff(.LC2), r1
        ;;
        (p7) addl r14 = 1, r0
        ;;
        .mib
        (p7) st4 [r15] = r14
        nop.i 0
        (p7) br.cond.dptk .L5
        .mib
        ld8 r14 = [r14]

And not ok if the MEM isn't exposed in RTL:
        addl r14 = @ltoff(ap_standalone#), r1
        ;;
        .mii
        ld8 r15 = [r14]
        addl r14 = @ltoff(.LC2), r1
        ;;
        (p7) addl r14 = 1, r0
        ;;
        .mii
        (p7) st4 [r15] = r14
        nop.i 0
        nop.i 0
        .mbb
        ld8 r14 = [r14]
        (p7) br.cond.dptk .L5

I'm attaching the 3.3 patch.


Bernd

Index: ../../branches/gcc-3_3-branch/gcc/sched-ebb.c
===================================================================
--- ../../branches/gcc-3_3-branch/gcc/sched-ebb.c       (revision 175226)
+++ ../../branches/gcc-3_3-branch/gcc/sched-ebb.c       (working copy)
@@ -52,8 +52,7 @@ static int schedule_more_p PARAMS ((void
 static const char *ebb_print_insn PARAMS ((rtx, int));
 static int rank PARAMS ((rtx, rtx));
 static int contributes_to_priority PARAMS ((rtx, rtx));
-static void compute_jump_reg_dependencies PARAMS ((rtx, regset, regset,
-                                                  regset));
+static void compute_jump_reg_dependencies PARAMS ((rtx, regset));
 static void schedule_ebb PARAMS ((rtx, rtx));
 
 /* Return nonzero if there are more insns that should be scheduled.  */
@@ -161,30 +160,22 @@ contributes_to_priority (next, insn)
   return 1;
 }
 
-/* INSN is a JUMP_INSN, COND_SET is the set of registers that are
-   conditionally set before INSN.  Store the set of registers that
-   must be considered as used by this jump in USED and that of
-   registers that must be considered as set in SET.  */
+/* INSN is a JUMP_INSN.  Store the set of registers that must be considered
+   to be set by this jump in SET.  */
 
 static void
-compute_jump_reg_dependencies (insn, cond_set, used, set)
+compute_jump_reg_dependencies (insn, set)
      rtx insn;
-     regset cond_set, used, set;
+     regset set;
 {
   basic_block b = BLOCK_FOR_INSN (insn);
   edge e;
   for (e = b->succ; e; e = e->succ_next)
-    if (e->flags & EDGE_FALLTHRU)
-      /* The jump may be a by-product of a branch that has been merged
-        in the main codepath after being conditionalized.  Therefore
-        it may guard the fallthrough block from using a value that has
-        conditionally overwritten that of the main codepath.  So we
-        consider that it restores the value of the main codepath.  */
-      bitmap_operation (set, e->dest->global_live_at_start, cond_set,
-                       BITMAP_AND);
-    else
-      bitmap_operation (used, used, e->dest->global_live_at_start,
-                       BITMAP_IOR);
+    if ((e->flags & EDGE_FALLTHRU) == 0)
+      {
+       bitmap_operation (set, set, e->dest->global_live_at_start,
+                         BITMAP_IOR);
+      }
 }
 
 /* Used in schedule_insns to initialize current_sched_info for scheduling
Index: ../../branches/gcc-3_3-branch/gcc/emit-rtl.c
===================================================================
--- ../../branches/gcc-3_3-branch/gcc/emit-rtl.c        (revision 175226)
+++ ../../branches/gcc-3_3-branch/gcc/emit-rtl.c        (working copy)
@@ -192,6 +192,18 @@ static tree component_ref_for_mem_expr     P
 static rtx gen_const_vector_0          PARAMS ((enum machine_mode));
 static void copy_rtx_if_shared_1       PARAMS ((rtx *orig));
 
+/* Generate a memory referring to non-trapping constant memory.  */
+
+rtx
+gen_const_mem (enum machine_mode mode, rtx addr)
+{
+  rtx mem = gen_rtx_MEM (mode, addr);
+  RTX_UNCHANGING_P (mem) = 1;
+  MEM_NOTRAP_P (mem) = 1;
+  return mem;
+}
+
+
 /* Probability of the conditional branch currently proceeded by try_split.
    Set to -1 otherwise.  */
 int split_branch_probability = -1;
Index: ../../branches/gcc-3_3-branch/gcc/sched-deps.c
===================================================================
--- ../../branches/gcc-3_3-branch/gcc/sched-deps.c      (revision 175226)
+++ ../../branches/gcc-3_3-branch/gcc/sched-deps.c      (working copy)
@@ -981,17 +981,12 @@ sched_analyze_insn (deps, x, insn, loop_
       else
        {
          rtx pending, pending_mem;
-         regset_head tmp_uses, tmp_sets;
-         INIT_REG_SET (&tmp_uses);
-         INIT_REG_SET (&tmp_sets);
-
-         (*current_sched_info->compute_jump_reg_dependencies)
-           (insn, &deps->reg_conditional_sets, &tmp_uses, &tmp_sets);
-         IOR_REG_SET (reg_pending_uses, &tmp_uses);
-         IOR_REG_SET (reg_pending_sets, &tmp_sets);
+         regset_head tmp;
+         INIT_REG_SET (&tmp);
 
-         CLEAR_REG_SET (&tmp_uses);
-         CLEAR_REG_SET (&tmp_sets);
+         (*current_sched_info->compute_jump_reg_dependencies) (insn, &tmp);
+         IOR_REG_SET (reg_pending_uses, &tmp);
+         CLEAR_REG_SET (&tmp);
 
          /* All memory writes and volatile reads must happen before the
             jump.  Non-volatile reads must happen before the jump iff
@@ -1088,7 +1083,6 @@ sched_analyze_insn (deps, x, insn, loop_
        }
 
       flush_pending_lists (deps, insn, true, true);
-      CLEAR_REG_SET (&deps->reg_conditional_sets);
       reg_pending_barrier = false;
     }
   else
@@ -1120,7 +1114,6 @@ sched_analyze_insn (deps, x, insn, loop_
              add_dependence_list (insn, reg_last->clobbers, REG_DEP_OUTPUT);
              add_dependence_list (insn, reg_last->uses, REG_DEP_ANTI);
              reg_last->sets = alloc_INSN_LIST (insn, reg_last->sets);
-             SET_REGNO_REG_SET (&deps->reg_conditional_sets, i);
            });
        }
       else
@@ -1169,7 +1162,6 @@ sched_analyze_insn (deps, x, insn, loop_
              reg_last->sets = alloc_INSN_LIST (insn, reg_last->sets);
              reg_last->uses_length = 0;
              reg_last->clobbers_length = 0;
-             CLEAR_REGNO_REG_SET (&deps->reg_conditional_sets, i);
            });
        }
 
@@ -1496,7 +1488,6 @@ init_deps (deps)
   deps->reg_last = (struct deps_reg *)
     xcalloc (max_reg, sizeof (struct deps_reg));
   INIT_REG_SET (&deps->reg_last_in_use);
-  INIT_REG_SET (&deps->reg_conditional_sets);
 
   deps->pending_read_insns = 0;
   deps->pending_read_mems = 0;
@@ -1539,7 +1530,6 @@ free_deps (deps)
        free_INSN_LIST_list (&reg_last->clobbers);
     });
   CLEAR_REG_SET (&deps->reg_last_in_use);
-  CLEAR_REG_SET (&deps->reg_conditional_sets);
 
   free (deps->reg_last);
 }
Index: ../../branches/gcc-3_3-branch/gcc/sched-int.h
===================================================================
--- ../../branches/gcc-3_3-branch/gcc/sched-int.h       (revision 175226)
+++ ../../branches/gcc-3_3-branch/gcc/sched-int.h       (working copy)
@@ -112,9 +112,6 @@ struct deps
   /* Element N is set for each register that has any nonzero element
      in reg_last[N].{uses,sets,clobbers}.  */
   regset_head reg_last_in_use;
-
-  /* Element N is set for each register that is conditionally set.  */
-  regset_head reg_conditional_sets;
 };
 
 /* This structure holds some state of the current scheduling pass, and
@@ -149,9 +146,9 @@ struct sched_info
      calculations.  */
   int (*contributes_to_priority) PARAMS ((rtx, rtx));
   /* Called when computing dependencies for a JUMP_INSN.  This function
-     should store the set of registers that must be considered as used
-     and the set of registers that must be considered as set by the jump.  */
-  void (*compute_jump_reg_dependencies) PARAMS ((rtx, regset, regset, regset));
+     should store the set of registers that must be considered as set by
+     the jump in the regset.  */
+  void (*compute_jump_reg_dependencies) PARAMS ((rtx, regset));
 
   /* The boundaries of the set of insns to be scheduled.  */
   rtx prev_head, next_tail;
Index: ../../branches/gcc-3_3-branch/gcc/sched-rgn.c
===================================================================
--- ../../branches/gcc-3_3-branch/gcc/sched-rgn.c       (revision 175226)
+++ ../../branches/gcc-3_3-branch/gcc/sched-rgn.c       (working copy)
@@ -1968,8 +1968,7 @@ static int schedule_more_p PARAMS ((void
 static const char *rgn_print_insn PARAMS ((rtx, int));
 static int rgn_rank PARAMS ((rtx, rtx));
 static int contributes_to_priority PARAMS ((rtx, rtx));
-static void compute_jump_reg_dependencies PARAMS ((rtx, regset, regset,
-                                                  regset));
+static void compute_jump_reg_dependencies PARAMS ((rtx, regset));
 
 /* Return nonzero if there are more insns that should be scheduled.  */
 
@@ -2256,16 +2255,12 @@ contributes_to_priority (next, insn)
   return BLOCK_NUM (next) == BLOCK_NUM (insn);
 }
 
-/* INSN is a JUMP_INSN, COND_SET is the set of registers that are
-   conditionally set before INSN.  Store the set of registers that
-   must be considered as used by this jump in USED and that of
-   registers that must be considered as set in SET.  */
+/* INSN is a JUMP_INSN.  Store the set of registers that must be considered
+   to be set by this jump in SET.  */
 
 static void
-compute_jump_reg_dependencies (insn, cond_set, used, set)
+compute_jump_reg_dependencies (insn, set)
      rtx insn ATTRIBUTE_UNUSED;
-     regset cond_set ATTRIBUTE_UNUSED;
-     regset used ATTRIBUTE_UNUSED;
      regset set ATTRIBUTE_UNUSED;
 {
   /* Nothing to do here, since we postprocess jumps in
Index: ../../branches/gcc-3_3-branch/gcc/config/ia64/ia64.md
===================================================================
--- ../../branches/gcc-3_3-branch/gcc/config/ia64/ia64.md       (revision 
175226)
+++ ../../branches/gcc-3_3-branch/gcc/config/ia64/ia64.md       (working copy)
@@ -534,13 +534,19 @@ (define_expand "load_symptr"
        (plus:DI (high:DI (match_operand:DI 1 "got_symbolic_operand" ""))
                 (match_dup 3)))
    (set (match_operand:DI 0 "register_operand" "")
-       (lo_sum:DI (match_dup 2) (match_dup 1)))]
+       (lo_sum:DI (mem:DI (match_dup 2)) (match_dup 1)))]
   ""
 {
   operands[3] = pic_offset_table_rtx;
+  emit_insn (gen_load_symptr_high (operands[2], operands[1], operands[3]));
+  emit_insn (gen_rtx_SET (VOIDmode, operands[0],
+                         gen_rtx_LO_SUM (DImode, gen_const_mem (DImode,
+                                                                operands[2]),
+                                         operands[1])));
+  DONE;
 })
 
-(define_insn "*load_symptr_high"
+(define_insn "load_symptr_high"
   [(set (match_operand:DI 0 "register_operand" "=r")
        (plus:DI (high:DI (match_operand 1 "got_symbolic_operand" "s"))
                 (match_operand:DI 2 "register_operand" "a")))]
@@ -555,7 +561,7 @@ (define_insn "*load_symptr_high"
 
 (define_insn "*load_symptr_low"
   [(set (match_operand:DI 0 "register_operand" "=r")
-       (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
+       (lo_sum:DI (mem:DI (match_operand:DI 1 "register_operand" "r"))
                   (match_operand 2 "got_symbolic_operand" "s")))]
   ""
 {

Reply via email to