diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 1677923a439..e36ef56a982 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -16363,6 +16363,15 @@ mem_loc_descriptor (rtx rtl, machine_mode mode, do_binop: op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, VAR_INIT_STATUS_INITIALIZED); + if (XEXP (rtl, 0) == XEXP (rtl, 1)) + { + if (op0 == 0) + break; + mem_loc_result = op0; + add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_dup, 0, 0)); + add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0)); + break; + } op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, VAR_INIT_STATUS_INITIALIZED); diff --git a/gcc/rtl.h b/gcc/rtl.h index 6a6de1cf11d..cf801be62c6 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -3433,6 +3433,14 @@ public: inside a MEM than outside. */ unsigned int mem_depth = 0; + /* Tracks number of simplify_associative_operation calls performed during + outermost simplify* call. */ + unsigned int assoc_count = 0; + + /* Limit for the above number, return NULL from + simplify_associative_operation after we reach that assoc_count. */ + static const unsigned int max_assoc_count = 64; + private: rtx simplify_truncation (machine_mode, rtx, machine_mode); rtx simplify_byte_swapping_operation (rtx_code, machine_mode, rtx, rtx); diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index eea747664d4..4fabd73382b 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2263,6 +2263,16 @@ simplify_context::simplify_associative_operation (rtx_code code, { rtx tem; + /* Normally expressions simplified by simplify-rtx.c are combined + at most from a few machine instructions and therefore the + expressions should be fairly small. During var-tracking + we can see arbitrarily large expressions though and reassociating + those can be quadratic, so punt after encountering max_assoc_count + simplify_associative_operation calls during outermost simplify_* + call. */ + if (++assoc_count >= max_assoc_count) + return NULL_RTX; + /* Linearize the operator to the left. */ if (GET_CODE (op1) == code) { diff --git a/gcc/testsuite/gcc.dg/pr102356.c b/gcc/testsuite/gcc.dg/pr102356.c new file mode 100644 index 00000000000..6fce77043cc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102356.c @@ -0,0 +1,33 @@ +/* PR rtl-optimization/102356 */ +/* { dg-do compile { target int32plus } } */ +/* { dg-options "-O3 -g" } */ + +signed char a = 0; +unsigned char b = 9; +unsigned long long c = 0xF1FBFC17225F7A57ULL; +int d = 0x3A6667C6; + +unsigned char +foo (unsigned int x) +{ + unsigned int *e = &x; + if ((c /= ((0 * (*e *= b)) <= 0))) + ; + for (d = 9; d > 2; d -= 2) + { + c = -2; + do + if ((*e *= *e)) + { + a = 4; + do + { + a -= 3; + if ((*e *= *e)) + b = 9; + } + while (a > 2); + } + while (c++); + } +}