[backport from gcc-4.6.4 r191315, for expedited testing ] gcc/ 2012-09-14 Wei Guozhi Backport from 2012-02-13 mainline r184169. * cselib.c (expand_loc): Return sp, fp, hfp or cfa base reg right away if seen. --- gcc-4.6.3/gcc/cselib.c.~1~ 2012-02-15 00:33:23.000000000 +0100 +++ gcc-4.6.3/gcc/cselib.c 2012-09-15 14:16:12.000000000 +0200 @@ -1237,8 +1237,18 @@ expand_loc (struct elt_loc_list *p, stru unsigned int regno = UINT_MAX; struct elt_loc_list *p_in = p; - for (; p; p = p -> next) + for (; p; p = p->next) { + /* Return these right away to avoid returning stack pointer based + expressions for frame pointer and vice versa, which is something + that would confuse DSE. See the comment in cselib_expand_value_rtx_1 + for more details. */ + if (REG_P (p->loc) + && (REGNO (p->loc) == STACK_POINTER_REGNUM + || REGNO (p->loc) == FRAME_POINTER_REGNUM + || REGNO (p->loc) == HARD_FRAME_POINTER_REGNUM + || REGNO (p->loc) == cfa_base_preserved_regno)) + return p->loc; /* Avoid infinite recursion trying to expand a reg into a the same reg. */ if ((REG_P (p->loc))