* [PATCH] Fix SLSR wrong-code (PR tree-optimization/56962)
@ 2013-04-15 15:21 Jakub Jelinek
2013-04-15 16:10 ` Bill Schmidt
2013-04-15 17:09 ` Richard Biener
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2013-04-15 15:21 UTC (permalink / raw)
To: Richard Biener, Bill Schmidt; +Cc: gcc-patches
Hi!
record_increment failed to verify that initializer is usable, which it is
only if cand_stmt is an addition (CAND_ADD can be e.g. even on a cast of
addition to some type of the same precision etc.) and one of the operands is
c->base_expr (because then the other operand necessarily has to be the rest,
but the code was only checking one of the operands, but cand_stmt e.g. can
be a sum of two SSA_NAMEs where each of those adds some multiply of one of
base_expr operands and some multiply of the c->stride. If we set
initializer to randomly chosen operand of such stmt, while we'll have the
right multiply of c->stride, the base_expr might be wrong.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/4.8?
2013-04-15 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/56962
* gimple-ssa-strength-reduction.c (record_increment): Only set
initializer if gimple_assign_rhs_code is {,POINTER_}PLUS_EXPR and
either rhs1 or rhs2 is equal to c->base_expr.
* gcc.c-torture/execute/pr56962.c: New test.
--- gcc/gimple-ssa-strength-reduction.c.jj 2013-01-11 09:02:50.000000000 +0100
+++ gcc/gimple-ssa-strength-reduction.c 2013-04-15 11:59:46.668463873 +0200
@@ -1829,16 +1829,20 @@ record_increment (slsr_cand_t c, double_
if (c->kind == CAND_ADD
&& c->index == increment
&& (increment.sgt (double_int_one)
- || increment.slt (double_int_minus_one)))
+ || increment.slt (double_int_minus_one))
+ && (gimple_assign_rhs_code (c->cand_stmt) == PLUS_EXPR
+ || gimple_assign_rhs_code (c->cand_stmt) == POINTER_PLUS_EXPR))
{
- tree t0;
+ tree t0 = NULL_TREE;
tree rhs1 = gimple_assign_rhs1 (c->cand_stmt);
tree rhs2 = gimple_assign_rhs2 (c->cand_stmt);
if (operand_equal_p (rhs1, c->base_expr, 0))
t0 = rhs2;
- else
+ else if (operand_equal_p (rhs2, c->base_expr, 0))
t0 = rhs1;
- if (SSA_NAME_DEF_STMT (t0) && gimple_bb (SSA_NAME_DEF_STMT (t0)))
+ if (t0
+ && SSA_NAME_DEF_STMT (t0)
+ && gimple_bb (SSA_NAME_DEF_STMT (t0)))
{
incr_vec[incr_vec_len].initializer = t0;
incr_vec[incr_vec_len++].init_bb
--- gcc/testsuite/gcc.c-torture/execute/pr56962.c.jj 2013-04-15 12:09:24.781355085 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr56962.c 2013-04-15 12:09:19.985381802 +0200
@@ -0,0 +1,30 @@
+/* PR tree-optimization/56962 */
+
+extern void abort (void);
+long long v[144];
+
+__attribute__((noinline, noclone)) void
+bar (long long *x)
+{
+ if (x != &v[29])
+ abort ();
+}
+
+__attribute__((noinline, noclone)) void
+foo (long long *x, long y, long z)
+{
+ long long a, b, c;
+ a = x[z * 4 + y * 3];
+ b = x[z * 5 + y * 3];
+ c = x[z * 5 + y * 4];
+ x[y * 4] = a;
+ bar (&x[z * 5 + y]);
+ x[z * 5 + y * 5] = b + c;
+}
+
+int
+main ()
+{
+ foo (v, 24, 1);
+ return 0;
+}
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix SLSR wrong-code (PR tree-optimization/56962)
2013-04-15 15:21 [PATCH] Fix SLSR wrong-code (PR tree-optimization/56962) Jakub Jelinek
@ 2013-04-15 16:10 ` Bill Schmidt
2013-04-15 17:09 ` Richard Biener
1 sibling, 0 replies; 3+ messages in thread
From: Bill Schmidt @ 2013-04-15 16:10 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Richard Biener, gcc-patches
FWIW, I agree with Jakub's fix. Thanks!
Bill
On Mon, 2013-04-15 at 16:28 +0200, Jakub Jelinek wrote:
> Hi!
>
> record_increment failed to verify that initializer is usable, which it is
> only if cand_stmt is an addition (CAND_ADD can be e.g. even on a cast of
> addition to some type of the same precision etc.) and one of the operands is
> c->base_expr (because then the other operand necessarily has to be the rest,
> but the code was only checking one of the operands, but cand_stmt e.g. can
> be a sum of two SSA_NAMEs where each of those adds some multiply of one of
> base_expr operands and some multiply of the c->stride. If we set
> initializer to randomly chosen operand of such stmt, while we'll have the
> right multiply of c->stride, the base_expr might be wrong.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk/4.8?
>
> 2013-04-15 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/56962
> * gimple-ssa-strength-reduction.c (record_increment): Only set
> initializer if gimple_assign_rhs_code is {,POINTER_}PLUS_EXPR and
> either rhs1 or rhs2 is equal to c->base_expr.
>
> * gcc.c-torture/execute/pr56962.c: New test.
>
> --- gcc/gimple-ssa-strength-reduction.c.jj 2013-01-11 09:02:50.000000000 +0100
> +++ gcc/gimple-ssa-strength-reduction.c 2013-04-15 11:59:46.668463873 +0200
> @@ -1829,16 +1829,20 @@ record_increment (slsr_cand_t c, double_
> if (c->kind == CAND_ADD
> && c->index == increment
> && (increment.sgt (double_int_one)
> - || increment.slt (double_int_minus_one)))
> + || increment.slt (double_int_minus_one))
> + && (gimple_assign_rhs_code (c->cand_stmt) == PLUS_EXPR
> + || gimple_assign_rhs_code (c->cand_stmt) == POINTER_PLUS_EXPR))
> {
> - tree t0;
> + tree t0 = NULL_TREE;
> tree rhs1 = gimple_assign_rhs1 (c->cand_stmt);
> tree rhs2 = gimple_assign_rhs2 (c->cand_stmt);
> if (operand_equal_p (rhs1, c->base_expr, 0))
> t0 = rhs2;
> - else
> + else if (operand_equal_p (rhs2, c->base_expr, 0))
> t0 = rhs1;
> - if (SSA_NAME_DEF_STMT (t0) && gimple_bb (SSA_NAME_DEF_STMT (t0)))
> + if (t0
> + && SSA_NAME_DEF_STMT (t0)
> + && gimple_bb (SSA_NAME_DEF_STMT (t0)))
> {
> incr_vec[incr_vec_len].initializer = t0;
> incr_vec[incr_vec_len++].init_bb
> --- gcc/testsuite/gcc.c-torture/execute/pr56962.c.jj 2013-04-15 12:09:24.781355085 +0200
> +++ gcc/testsuite/gcc.c-torture/execute/pr56962.c 2013-04-15 12:09:19.985381802 +0200
> @@ -0,0 +1,30 @@
> +/* PR tree-optimization/56962 */
> +
> +extern void abort (void);
> +long long v[144];
> +
> +__attribute__((noinline, noclone)) void
> +bar (long long *x)
> +{
> + if (x != &v[29])
> + abort ();
> +}
> +
> +__attribute__((noinline, noclone)) void
> +foo (long long *x, long y, long z)
> +{
> + long long a, b, c;
> + a = x[z * 4 + y * 3];
> + b = x[z * 5 + y * 3];
> + c = x[z * 5 + y * 4];
> + x[y * 4] = a;
> + bar (&x[z * 5 + y]);
> + x[z * 5 + y * 5] = b + c;
> +}
> +
> +int
> +main ()
> +{
> + foo (v, 24, 1);
> + return 0;
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix SLSR wrong-code (PR tree-optimization/56962)
2013-04-15 15:21 [PATCH] Fix SLSR wrong-code (PR tree-optimization/56962) Jakub Jelinek
2013-04-15 16:10 ` Bill Schmidt
@ 2013-04-15 17:09 ` Richard Biener
1 sibling, 0 replies; 3+ messages in thread
From: Richard Biener @ 2013-04-15 17:09 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Bill Schmidt, gcc-patches
On Mon, 15 Apr 2013, Jakub Jelinek wrote:
> Hi!
>
> record_increment failed to verify that initializer is usable, which it is
> only if cand_stmt is an addition (CAND_ADD can be e.g. even on a cast of
> addition to some type of the same precision etc.) and one of the operands is
> c->base_expr (because then the other operand necessarily has to be the rest,
> but the code was only checking one of the operands, but cand_stmt e.g. can
> be a sum of two SSA_NAMEs where each of those adds some multiply of one of
> base_expr operands and some multiply of the c->stride. If we set
> initializer to randomly chosen operand of such stmt, while we'll have the
> right multiply of c->stride, the base_expr might be wrong.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk/4.8?
Ok.
Thanks,
Richard.
> 2013-04-15 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/56962
> * gimple-ssa-strength-reduction.c (record_increment): Only set
> initializer if gimple_assign_rhs_code is {,POINTER_}PLUS_EXPR and
> either rhs1 or rhs2 is equal to c->base_expr.
>
> * gcc.c-torture/execute/pr56962.c: New test.
>
> --- gcc/gimple-ssa-strength-reduction.c.jj 2013-01-11 09:02:50.000000000 +0100
> +++ gcc/gimple-ssa-strength-reduction.c 2013-04-15 11:59:46.668463873 +0200
> @@ -1829,16 +1829,20 @@ record_increment (slsr_cand_t c, double_
> if (c->kind == CAND_ADD
> && c->index == increment
> && (increment.sgt (double_int_one)
> - || increment.slt (double_int_minus_one)))
> + || increment.slt (double_int_minus_one))
> + && (gimple_assign_rhs_code (c->cand_stmt) == PLUS_EXPR
> + || gimple_assign_rhs_code (c->cand_stmt) == POINTER_PLUS_EXPR))
> {
> - tree t0;
> + tree t0 = NULL_TREE;
> tree rhs1 = gimple_assign_rhs1 (c->cand_stmt);
> tree rhs2 = gimple_assign_rhs2 (c->cand_stmt);
> if (operand_equal_p (rhs1, c->base_expr, 0))
> t0 = rhs2;
> - else
> + else if (operand_equal_p (rhs2, c->base_expr, 0))
> t0 = rhs1;
> - if (SSA_NAME_DEF_STMT (t0) && gimple_bb (SSA_NAME_DEF_STMT (t0)))
> + if (t0
> + && SSA_NAME_DEF_STMT (t0)
> + && gimple_bb (SSA_NAME_DEF_STMT (t0)))
> {
> incr_vec[incr_vec_len].initializer = t0;
> incr_vec[incr_vec_len++].init_bb
> --- gcc/testsuite/gcc.c-torture/execute/pr56962.c.jj 2013-04-15 12:09:24.781355085 +0200
> +++ gcc/testsuite/gcc.c-torture/execute/pr56962.c 2013-04-15 12:09:19.985381802 +0200
> @@ -0,0 +1,30 @@
> +/* PR tree-optimization/56962 */
> +
> +extern void abort (void);
> +long long v[144];
> +
> +__attribute__((noinline, noclone)) void
> +bar (long long *x)
> +{
> + if (x != &v[29])
> + abort ();
> +}
> +
> +__attribute__((noinline, noclone)) void
> +foo (long long *x, long y, long z)
> +{
> + long long a, b, c;
> + a = x[z * 4 + y * 3];
> + b = x[z * 5 + y * 3];
> + c = x[z * 5 + y * 4];
> + x[y * 4] = a;
> + bar (&x[z * 5 + y]);
> + x[z * 5 + y * 5] = b + c;
> +}
> +
> +int
> +main ()
> +{
> + foo (v, 24, 1);
> + return 0;
> +}
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-04-15 14:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-15 15:21 [PATCH] Fix SLSR wrong-code (PR tree-optimization/56962) Jakub Jelinek
2013-04-15 16:10 ` Bill Schmidt
2013-04-15 17:09 ` Richard Biener
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).