public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body.
@ 2013-09-23 18:23 congh at google dot com
2013-09-24 7:47 ` [Bug tree-optimization/58508] [Missed-Optimization] " rguenth at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: congh at google dot com @ 2013-09-23 18:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
Bug ID: 58508
Summary: Redundant vector load of "actual" loop invariant in
loop body.
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: congh at google dot com
When GCC vectorizes the loop below, it will firstly do loop versioning with
aliasing check on a and b. Since a and b have different strides (1 and 0), the
check guarantees that there is no aliasing between a and b across all
iterations. Then with this precondition *b becomes a loop invariant so that it
can be loaded outside the loop during vectorization (Note that this
precondition always holds when the loop is being vectorized). This can save us
a load and a shuffle instruction in each iteration.
void foo (int* a, int* b, int n)
{
for (int i = 0; i < n; ++i)
a[i] += *b;
}
I have a patch handling this case as an optimization. After loop versioning, I
detect all zero-strided data references and hoist the loads of them to the loop
header. The patch is shown below.
thanks,
Cong
Index: gcc/tree-vect-loop-manip.c
===================================================================
--- gcc/tree-vect-loop-manip.c (revision 202662)
+++ gcc/tree-vect-loop-manip.c (working copy)
@@ -2477,6 +2477,37 @@ vect_loop_versioning (loop_vec_info loop
adjust_phi_and_debug_stmts (orig_phi, e, PHI_RESULT (new_phi));
}
+ /* Extract load and store statements on pointers with zero-stride
+ accesses. */
+ if (LOOP_REQUIRES_VERSIONING_FOR_ALIAS (loop_vinfo))
+ {
+
+ /* In the loop body, we iterate each statement to check if it is a load
+ or store. Then we check the DR_STEP of the data reference. If
+ DR_STEP is zero, then we will hoist the load statement to the loop
+ preheader, and move the store statement to the loop exit. */
+
+ for (gimple_stmt_iterator si = gsi_start_bb (loop->header);
+ !gsi_end_p (si); )
+ {
+ gimple stmt = gsi_stmt (si);
+ stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
+ struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
+
+ if (dr && integer_zerop (DR_STEP (dr)))
+ {
+ if (DR_IS_READ (dr))
+ {
+ basic_block preheader = loop_preheader_edge (loop)->src;
+ gimple_stmt_iterator si_dst = gsi_last_bb (preheader);
+ gsi_move_after (&si, &si_dst);
+ }
+ }
+ else
+ gsi_next (&si);
+ }
+ }
+
/* End loop-exit-fixes after versioning. */
if (cond_expr_stmt_list)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
@ 2013-09-24 7:47 ` rguenth at gcc dot gnu.org
2013-10-15 20:57 ` congh at google dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-09-24 7:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-09-24
Blocks| |53947
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
While the observation is correct, the fix is not. Please just emit the
load on the preheader edge, like we do for other dt_external vectors we
materialize.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
2013-09-24 7:47 ` [Bug tree-optimization/58508] [Missed-Optimization] " rguenth at gcc dot gnu.org
@ 2013-10-15 20:57 ` congh at google dot com
2013-10-19 5:20 ` law at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: congh at google dot com @ 2013-10-15 20:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
--- Comment #2 from Cong Hou <congh at google dot com> ---
Thank you for the comment. I have modified the patch by using
gsi_insert_on_edge_immediate (loop_preheader_edge (loop), stmt);
to move the statement.
I have sent this patch again.
Thank you!
Cong
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
2013-09-24 7:47 ` [Bug tree-optimization/58508] [Missed-Optimization] " rguenth at gcc dot gnu.org
2013-10-15 20:57 ` congh at google dot com
@ 2013-10-19 5:20 ` law at gcc dot gnu.org
2013-10-29 0:09 ` congh at google dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: law at gcc dot gnu.org @ 2013-10-19 5:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
--- Comment #3 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Author: law
Date: Sat Oct 19 05:20:24 2013
New Revision: 203842
URL: http://gcc.gnu.org/viewcvs?rev=203842&root=gcc&view=rev
Log:
PR tree-optimization/58508
* tree-vect-loop-manip.c (vect_loop_versioning): Hoist loop invariant
statement that contains data refs with zero-step.
* gcc.dg/vect/pr58508.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/vect/pr58508.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-vect-loop-manip.c
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
` (2 preceding siblings ...)
2013-10-19 5:20 ` law at gcc dot gnu.org
@ 2013-10-29 0:09 ` congh at google dot com
2013-10-29 13:50 ` bernd.edlinger at hotmail dot de
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: congh at google dot com @ 2013-10-29 0:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
--- Comment #5 from Cong Hou <congh at google dot com> ---
I guess I should add
/* { dg-require-effective-target vect_int } */
to the test case. It is right?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
` (3 preceding siblings ...)
2013-10-29 0:09 ` congh at google dot com
@ 2013-10-29 13:50 ` bernd.edlinger at hotmail dot de
2013-10-29 17:22 ` congh at google dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bernd.edlinger at hotmail dot de @ 2013-10-29 13:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
--- Comment #6 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
(In reply to Cong Hou from comment #5)
> I guess I should add
>
> /* { dg-require-effective-target vect_int } */
>
> to the test case. It is right?
Yes.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
` (4 preceding siblings ...)
2013-10-29 13:50 ` bernd.edlinger at hotmail dot de
@ 2013-10-29 17:22 ` congh at google dot com
2013-11-08 19:11 ` congh at gcc dot gnu.org
2013-11-11 19:31 ` congh at google dot com
7 siblings, 0 replies; 9+ messages in thread
From: congh at google dot com @ 2013-10-29 17:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
--- Comment #7 from Cong Hou <congh at google dot com> ---
OK. I made a new patch to fix this problem. Waiting to be approved.
thanks,
Cong
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9d0f4a5..3d9916d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2013-10-29 Cong Hou <congh@google.com>
+
+ * gcc.dg/vect/pr58508.c: Update.
+
2013-10-15 Cong Hou <congh@google.com>
* gcc.dg/vect/pr58508.c: New test.
diff --git a/gcc/testsuite/gcc.dg/vect/pr58508.c
b/gcc/testsuite/gcc.dg/vect/pr58508.c
index 6484a65..fff7a04 100644
--- a/gcc/testsuite/gcc.dg/vect/pr58508.c
+++ b/gcc/testsuite/gcc.dg/vect/pr58508.c
@@ -1,3 +1,4 @@
+/* { dg-require-effective-target vect_int } */
/* { dg-do compile } */
/* { dg-options "-O2 -ftree-vectorize -fdump-tree-vect-details" } */
On Tue, Oct 29, 2013 at 6:50 AM, bernd.edlinger at hotmail dot de
<gcc-bugzilla@gcc.gnu.org> wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
>
> --- Comment #6 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
> (In reply to Cong Hou from comment #5)
>> I guess I should add
>>
>> /* { dg-require-effective-target vect_int } */
>>
>> to the test case. It is right?
>
> Yes.
>
> --
> You are receiving this mail because:
> You reported the bug.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
` (5 preceding siblings ...)
2013-10-29 17:22 ` congh at google dot com
@ 2013-11-08 19:11 ` congh at gcc dot gnu.org
2013-11-11 19:31 ` congh at google dot com
7 siblings, 0 replies; 9+ messages in thread
From: congh at gcc dot gnu.org @ 2013-11-08 19:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
--- Comment #8 from congh at gcc dot gnu.org ---
Author: congh
Date: Fri Nov 8 18:44:46 2013
New Revision: 204590
URL: http://gcc.gnu.org/viewcvs?rev=204590&root=gcc&view=rev
Log:
2013-11-08 Cong Hou <congh@google.com>
PR tree-optimization/58508
* gcc.dg/vect/pr58508.c: Update.
Modified:
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/vect/pr58508.c
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/58508] [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
` (6 preceding siblings ...)
2013-11-08 19:11 ` congh at gcc dot gnu.org
@ 2013-11-11 19:31 ` congh at google dot com
7 siblings, 0 replies; 9+ messages in thread
From: congh at google dot com @ 2013-11-11 19:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58508
Cong Hou <congh at google dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #9 from Cong Hou <congh at google dot com> ---
(In reply to congh from comment #8)
> Author: congh
> Date: Fri Nov 8 18:44:46 2013
> New Revision: 204590
>
> URL: http://gcc.gnu.org/viewcvs?rev=204590&root=gcc&view=rev
> Log:
> 2013-11-08 Cong Hou <congh@google.com>
>
> PR tree-optimization/58508
> * gcc.dg/vect/pr58508.c: Update.
>
>
> Modified:
> trunk/gcc/testsuite/ChangeLog
> trunk/gcc/testsuite/gcc.dg/vect/pr58508.c
>From gcc-bugs-return-434303-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Nov 11 19:31:50 2013
Return-Path: <gcc-bugs-return-434303-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 2474 invoked by alias); 11 Nov 2013 19:31:50 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 2406 invoked by uid 48); 11 Nov 2013 19:31:46 -0000
From: "congh at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/53947] [meta-bug] vectorizer missed-optimizations
Date: Mon, 11 Nov 2013 19:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 4.8.0
X-Bugzilla-Keywords: meta-bug, missed-optimization
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: congh at google dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution
Message-ID: <bug-53947-4-W23x23DfyE@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-53947-4@http.gcc.gnu.org/bugzilla/>
References: <bug-53947-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-11/txt/msg01080.txt.bz2
Content-length: 506
http://gcc.gnu.org/bugzilla/show_bug.cgi?idS947
Bug 53947 depends on bug 58508, which changed state.
Bug 58508 Summary: [Missed-Optimization] Redundant vector load of "actual" loop invariant in loop body.
http://gcc.gnu.org/bugzilla/show_bug.cgi?idX508
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-11-11 19:31 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-23 18:23 [Bug tree-optimization/58508] New: Redundant vector load of "actual" loop invariant in loop body congh at google dot com
2013-09-24 7:47 ` [Bug tree-optimization/58508] [Missed-Optimization] " rguenth at gcc dot gnu.org
2013-10-15 20:57 ` congh at google dot com
2013-10-19 5:20 ` law at gcc dot gnu.org
2013-10-29 0:09 ` congh at google dot com
2013-10-29 13:50 ` bernd.edlinger at hotmail dot de
2013-10-29 17:22 ` congh at google dot com
2013-11-08 19:11 ` congh at gcc dot gnu.org
2013-11-11 19:31 ` congh at google dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).