From 358f3a0662b79de06420e7aa96864b6e43a063d3 Mon Sep 17 00:00:00 2001 From: rsandifo Date: Mon, 3 Jul 2017 07:26:21 +0000 Subject: [PATCH] Tweak BB analysis for dr_analyze_innermost dr_analyze_innermost had a "struct loop *nest" parameter that acted like a boolean. This was added in r179161, with the idea that a null nest selected BB-level analysis rather than loop analysis. The handling seemed strange though. If the DR was part of a loop, we still tried to express the base and offset values as IVs, potentially giving a nonzero step. If that failed for any reason, we'd revert to using the original base and offset, just as we would if we hadn't asked for an IV in the first place. It seems more natural to use the !in_loop handling whenever nest is null and always set the step to zero. This actually enables one more SLP opportunity in bb-slp-pr65935.c. I checked out r179161 and tried the patch there. The test case added in that revision still passes, so I don't think there was any particular need to check simple_iv. 2017-06-28 Richard Sandiford gcc/ * tree-data-ref.c (dr_analyze_innermost): Replace the "nest" parameter with a "loop" parameter and use it instead of the loop containing DR_STMT. Don't check simple_iv when doing BB analysis. Describe the two analysis modes in the comment. gcc/testsuite/ * gcc.dg/vect/bb-slp-pr65935.c: Expect SLP to be used in main as well. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249896 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 ++++ gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/vect/bb-slp-pr65935.c | 4 +- gcc/tree-data-ref.c | 66 +++++++++++++----------------- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c95a82fd351..08657e0accf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-07-03 Richard Sandiford + + * tree-data-ref.c (dr_analyze_innermost): Replace the "nest" + parameter with a "loop" parameter and use it instead of the + loop containing DR_STMT. Don't check simple_iv when doing + BB analysis. Describe the two analysis modes in the comment. + 2017-07-03 Tom de Vries PR tree-optimization/69468 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c52c7a83814..f5d2f8be789 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-07-03 Richard Sandiford + + * gcc.dg/vect/bb-slp-pr65935.c: Expect SLP to be used in main + as well. + 2017-07-03 Tom de Vries PR tree-optimization/69468 diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr65935.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr65935.c index a6c75c7c77f..0e4f1a71b6b 100644 --- a/gcc/testsuite/gcc.dg/vect/bb-slp-pr65935.c +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr65935.c @@ -57,4 +57,6 @@ int main() return 0; } -/* { dg-final { scan-tree-dump-times "basic block vectorized" 1 "slp1" } } */ +/* We should also be able to use 2-lane SLP to initialize the real and + imaginary components in the first loop of main. */ +/* { dg-final { scan-tree-dump-times "basic block vectorized" 2 "slp1" } } */ diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c index ba473021534..0fcefdc43b1 100644 --- a/gcc/tree-data-ref.c +++ b/gcc/tree-data-ref.c @@ -749,15 +749,29 @@ canonicalize_base_object_address (tree addr) return build_fold_addr_expr (TREE_OPERAND (addr, 0)); } -/* Analyzes the behavior of the memory reference DR in the innermost loop or - basic block that contains it. Returns true if analysis succeed or false - otherwise. */ +/* Analyze the behavior of memory reference DR. There are two modes: + + - BB analysis. In this case we simply split the address into base, + init and offset components, without reference to any containing loop. + The resulting base and offset are general expressions and they can + vary arbitrarily from one iteration of the containing loop to the next. + The step is always zero. + + - loop analysis. In this case we analyze the reference both wrt LOOP + and on the basis that the reference occurs (is "used") in LOOP; + see the comment above analyze_scalar_evolution_in_loop for more + information about this distinction. The base, init, offset and + step fields are all invariant in LOOP. + + Perform BB analysis if LOOP is null, or if LOOP is the function's + dummy outermost loop. In other cases perform loop analysis. + + Return true if the analysis succeeded and store the results in DR if so. + BB analysis can only fail for bitfield or reversed-storage accesses. */ bool -dr_analyze_innermost (struct data_reference *dr, struct loop *nest) +dr_analyze_innermost (struct data_reference *dr, struct loop *loop) { - gimple *stmt = DR_STMT (dr); - struct loop *loop = loop_containing_stmt (stmt); tree ref = DR_REF (dr); HOST_WIDE_INT pbitsize, pbitpos; tree base, poffset; @@ -806,22 +820,11 @@ dr_analyze_innermost (struct data_reference *dr, struct loop *nest) if (in_loop) { - if (!simple_iv (loop, loop_containing_stmt (stmt), base, &base_iv, - nest ? true : false)) + if (!simple_iv (loop, loop, base, &base_iv, true)) { - if (nest) - { - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "failed: evolution of base is not" - " affine.\n"); - return false; - } - else - { - base_iv.base = base; - base_iv.step = ssize_int (0); - base_iv.no_overflow = true; - } + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "failed: evolution of base is not affine.\n"); + return false; } } else @@ -843,22 +846,11 @@ dr_analyze_innermost (struct data_reference *dr, struct loop *nest) offset_iv.base = poffset; offset_iv.step = ssize_int (0); } - else if (!simple_iv (loop, loop_containing_stmt (stmt), - poffset, &offset_iv, - nest ? true : false)) + else if (!simple_iv (loop, loop, poffset, &offset_iv, true)) { - if (nest) - { - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "failed: evolution of offset is not" - " affine.\n"); - return false; - } - else - { - offset_iv.base = poffset; - offset_iv.step = ssize_int (0); - } + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "failed: evolution of offset is not affine.\n"); + return false; } } @@ -1077,7 +1069,7 @@ create_data_ref (loop_p nest, loop_p loop, tree memref, gimple *stmt, DR_REF (dr) = memref; DR_IS_READ (dr) = is_read; - dr_analyze_innermost (dr, nest); + dr_analyze_innermost (dr, nest != NULL ? loop : NULL); dr_analyze_indices (dr, nest, loop); dr_analyze_alias (dr); -- 2.11.4.GIT