1 diff -Naurp gcc/alias.c gcc/alias.c
2 --- gcc/alias.c 2012-03-01 22:28:11.000000000 +0530
3 +++ gcc/alias.c 2012-11-06 15:25:38.000000000 +0530
4 @@ -1595,6 +1595,9 @@ find_base_term (rtx x)
8 + if (cselib_sp_based_value_p (val))
9 + return static_reg_base_value[STACK_POINTER_REGNUM];
12 /* Temporarily reset val->locs to avoid infinite recursion. */
14 diff -Naurp gcc/cselib.c gcc/cselib.c
15 --- gcc/cselib.c 2012-03-01 22:28:11.000000000 +0530
16 +++ gcc/cselib.c 2012-11-06 15:25:38.000000000 +0530
17 @@ -209,6 +209,9 @@ void (*cselib_record_sets_hook) (rtx ins
18 #define PRESERVED_VALUE_P(RTX) \
19 (RTL_FLAG_CHECK1("PRESERVED_VALUE_P", (RTX), VALUE)->unchanging)
21 +#define SP_BASED_VALUE_P(RTX) \
22 + (RTL_FLAG_CHECK1("SP_BASED_VALUE_P", (RTX), VALUE)->jump)
26 /* Allocate a struct elt_list and fill in its two elements with the
27 @@ -738,6 +741,23 @@ cselib_preserve_only_values (void)
28 gcc_assert (first_containing_mem == &dummy_val);
31 +/* Arrange for a value to be marked as based on stack pointer
32 + for find_base_term purposes. */
35 +cselib_set_value_sp_based (cselib_val *v)
37 + SP_BASED_VALUE_P (v->val_rtx) = 1;
40 +/* Test whether a value is preserved. */
43 +cselib_sp_based_value_p (cselib_val *v)
45 + return SP_BASED_VALUE_P (v->val_rtx);
48 /* Return the mode in which a register was last set. If X is not a
49 register, return its mode. If the mode in which the register was
50 set is not known, or the value was already clobbered, return
51 diff -Naurp gcc/cselib.h gcc/cselib.h
52 --- gcc/cselib.h 2012-03-01 22:28:11.000000000 +0530
53 +++ gcc/cselib.h 2012-11-06 15:25:38.000000000 +0530
54 @@ -99,6 +99,8 @@ extern void cselib_preserve_only_values
55 extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int);
56 extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx);
57 extern bool cselib_have_permanent_equivalences (void);
58 +extern void cselib_set_value_sp_based (cselib_val *);
59 +extern bool cselib_sp_based_value_p (cselib_val *);
61 extern void dump_cselib_table (FILE *);
63 diff -Naurp gcc/rtl.h gcc/rtl.h
64 --- gcc/rtl.h 2012-01-25 00:36:38.000000000 +0530
65 +++ gcc/rtl.h 2012-11-06 15:25:38.000000000 +0530
66 @@ -266,7 +266,8 @@ struct GTY((chain_next ("RTX_NEXT (&%h)"
67 1 in a CALL_INSN if it is a sibling call.
68 1 in a SET that is for a return.
69 In a CODE_LABEL, part of the two-bit alternate entry field.
70 - 1 in a CONCAT is VAL_EXPR_IS_COPIED in var-tracking.c. */
71 + 1 in a CONCAT is VAL_EXPR_IS_COPIED in var-tracking.c.
72 + 1 in a VALUE is SP_BASED_VALUE_P in cselib.c. */
73 unsigned int jump : 1;
74 /* In a CODE_LABEL, part of the two-bit alternate entry field.
75 1 in a MEM if it cannot trap.
76 diff -Naurp gcc/testsuite/gcc.dg/guality/pr54796.c gcc/testsuite/gcc.dg/guality/pr54796.c
77 --- gcc/testsuite/gcc.dg/guality/pr54796.c 1970-01-01 05:30:00.000000000 +0530
78 +++ gcc/testsuite/gcc.dg/guality/pr54796.c 2012-11-06 15:25:38.000000000 +0530
82 +/* { dg-options "-g" } */
84 +__attribute__((noinline, noclone)) void
87 + __asm volatile ("" : "+r" (a), "+r" (b) : : "memory");
90 +__attribute__((noinline, noclone)) void
94 + char d[b]; /* { dg-final { gdb-test 17 "a" "5" } } */
95 + bar (d, 2); /* { dg-final { gdb-test 17 "b" "6" } } */
96 + bar (d, 4); /* { dg-final { gdb-test 17 "c" "5" } } */
105 diff -Naurp gcc/var-tracking.c gcc/var-tracking.c
106 --- gcc/var-tracking.c 2012-02-25 17:39:27.000000000 +0530
107 +++ gcc/var-tracking.c 2012-11-06 15:25:38.000000000 +0530
108 @@ -5521,6 +5521,11 @@ add_stores (rtx loc, const_rtx expr, voi
110 resolve = preserve = !cselib_preserved_value_p (v);
112 + if (loc == stack_pointer_rtx
113 + && hard_frame_pointer_adjustment != -1
115 + cselib_set_value_sp_based (v);
117 nloc = replace_expr_with_values (oloc);
120 @@ -9446,6 +9451,19 @@ vt_initialize (void)
123 hard_frame_pointer_adjustment = fp_cfa_offset;
124 + /* Disassociate sp from fp now. */
125 + if (MAY_HAVE_DEBUG_INSNS)
128 + cselib_invalidate_rtx (stack_pointer_rtx);
129 + v = cselib_lookup (stack_pointer_rtx, Pmode, 1,
131 + if (v && !cselib_preserved_value_p (v))
133 + cselib_set_value_sp_based (v);
134 + preserve_value (v);