On Mon, Jan 18, 2016 at 11:40:23AM +0100, Eric Botcazou wrote: > > So, do you suggest to tweak get_addr like the patch below, and remove the > > mem_addr = get_addr (mem_addr); > > line above and the comment? > > Yes, exactly. And if that doesn't easily work, then go for your solution and > add a blurb to the comment explaining why get_addr cannot be easily changed.
Bootstrap/regtest passed on x86_64-linux and i686-linux, ok for trunk? No changes in DSE locally_deleted/globally_deleted statistics from x86_64-linux and i686-linux bootstraps/regtests seen (unpatched vs patched compiler), other than in the testcase from this PR on i686-linux -O3 -g, and varying number of compilations of struct-layout-1_generate.c (but always the same number of DSE deleted insns in them) due to make -jN -k check (the generator # of compilations/invocations depends on scheduling of the make check tasks, unlike the number of actual testings). 2016-01-19 Jakub Jelinek <ja...@redhat.com> PR rtl-optimization/68955 PR rtl-optimization/64557 * dse.c (record_store, check_mem_read_rtx): Don't call get_addr here. Fix up formatting. * alias.c (get_addr): Handle VALUE + CONST_INT. * gcc.dg/torture/pr68955.c: New test. --- gcc/dse.c.jj 2016-01-15 20:37:24.000000000 +0100 +++ gcc/dse.c 2016-01-18 12:18:04.115988214 +0100 @@ -1515,14 +1515,9 @@ record_store (rtx body, bb_info_t bb_inf mem_addr = base->val_rtx; else { - group_info *group - = rtx_group_vec[group_id]; + group_info *group = rtx_group_vec[group_id]; mem_addr = group->canon_base_addr; } - /* get_addr can only handle VALUE but cannot handle expr like: - VALUE + OFFSET, so call get_addr to get original addr for - mem_addr before plus_constant. */ - mem_addr = get_addr (mem_addr); if (offset) mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset); } @@ -2128,14 +2123,9 @@ check_mem_read_rtx (rtx *loc, bb_info_t mem_addr = base->val_rtx; else { - group_info *group - = rtx_group_vec[group_id]; + group_info *group = rtx_group_vec[group_id]; mem_addr = group->canon_base_addr; } - /* get_addr can only handle VALUE but cannot handle expr like: - VALUE + OFFSET, so call get_addr to get original addr for - mem_addr before plus_constant. */ - mem_addr = get_addr (mem_addr); if (offset) mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset); } --- gcc/alias.c.jj 2016-01-14 17:01:09.000000000 +0100 +++ gcc/alias.c 2016-01-18 10:30:46.780994699 +0100 @@ -2203,7 +2203,23 @@ get_addr (rtx x) struct elt_loc_list *l; if (GET_CODE (x) != VALUE) - return x; + { + if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS) + && GET_CODE (XEXP (x, 0)) == VALUE + && CONST_SCALAR_INT_P (XEXP (x, 1))) + { + rtx op0 = get_addr (XEXP (x, 0)); + if (op0 != XEXP (x, 0)) + { + if (GET_CODE (x) == PLUS + && GET_CODE (XEXP (x, 1)) == CONST_INT) + return plus_constant (GET_MODE (x), op0, INTVAL (XEXP (x, 1))); + return simplify_gen_binary (GET_CODE (x), GET_MODE (x), + op0, XEXP (x, 1)); + } + } + return x; + } v = CSELIB_VAL_PTR (x); if (v) { --- gcc/testsuite/gcc.dg/torture/pr68955.c.jj 2016-01-18 12:18:31.254612960 +0100 +++ gcc/testsuite/gcc.dg/torture/pr68955.c 2016-01-18 12:18:31.254612960 +0100 @@ -0,0 +1,41 @@ +/* PR rtl-optimization/68955 */ +/* { dg-do run } */ +/* { dg-output "ONE1ONE" } */ + +int a, b, c, d, g, m; +int i[7][7][5] = { { { 5 } }, { { 5 } }, + { { 5 }, { 5 }, { 5 }, { 5 }, { 5 }, { -1 } } }; +static int j = 11; +short e, f, h, k, l; + +static void +foo () +{ + for (; e < 5; e++) + for (h = 3; h; h--) + { + for (g = 1; g < 6; g++) + { + m = c == 0 ? b : b / c; + i[e][1][e] = i[1][1][1] | (m & l) && f; + } + for (k = 0; k < 6; k++) + { + for (d = 0; d < 6; d++) + i[1][e][h] = i[h][k][e] >= l; + i[e + 2][h + 3][e] = 6 & l; + i[2][1][2] = a; + for (; j < 5;) + for (;;) + ; + } + } +} + +int +main () +{ + foo (); + __builtin_printf ("ONE%dONE\n", i[1][0][2]); + return 0; +} Jakub