* 3 further backports to 6.3
@ 2016-12-09 12:50 Jakub Jelinek
2016-12-09 12:57 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-12-09 12:50 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 277 bytes --]
Hi!
My tree-ssa-reassoc.c fix backport for 6 branch depends on 2 other patches,
where the testcases don't fail on the branch for those 2, but the issue has
been just latent. Are these ok to backport to 6.3 too?
Bootstrapped/regtested on x86_64-linux and i686-linux.
Jakub
[-- Attachment #2: r240299 --]
[-- Type: text/plain, Size: 4335 bytes --]
2016-12-09 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
2016-09-21 Kugan Vivekanandarajah <kuganv@linaro.org>
PR tree-optimization/72835
* tree-ssa-reassoc.c (make_new_ssa_for_def): New.
(make_new_ssa_for_all_defs): Likewise.
(zero_one_operation): Replace all SSA_NAMEs defined in the chain.
* gcc.dg/tree-ssa/pr72835.c: New test.
--- gcc/tree-ssa-reassoc.c (revision 240298)
+++ gcc/tree-ssa-reassoc.c (revision 240299)
@@ -1143,6 +1143,52 @@ decrement_power (gimple *stmt)
}
}
+/* Replace SSA defined by STMT and replace all its uses with new
+ SSA. Also return the new SSA. */
+
+static tree
+make_new_ssa_for_def (gimple *stmt)
+{
+ gimple *use_stmt;
+ use_operand_p use;
+ imm_use_iterator iter;
+ tree new_lhs;
+ tree lhs = gimple_assign_lhs (stmt);
+
+ new_lhs = make_ssa_name (TREE_TYPE (lhs));
+ gimple_set_lhs (stmt, new_lhs);
+
+ /* Also need to update GIMPLE_DEBUGs. */
+ FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
+ {
+ FOR_EACH_IMM_USE_ON_STMT (use, iter)
+ SET_USE (use, new_lhs);
+ update_stmt (use_stmt);
+ }
+ return new_lhs;
+}
+
+/* Replace all SSAs defined in STMTS_TO_FIX and replace its
+ uses with new SSAs. Also do this for the stmt that defines DEF
+ if *DEF is not OP. */
+
+static void
+make_new_ssa_for_all_defs (tree *def, tree op,
+ vec<gimple *> &stmts_to_fix)
+{
+ unsigned i;
+ gimple *stmt;
+
+ if (*def != op
+ && TREE_CODE (*def) == SSA_NAME
+ && (stmt = SSA_NAME_DEF_STMT (*def))
+ && gimple_code (stmt) != GIMPLE_NOP)
+ *def = make_new_ssa_for_def (stmt);
+
+ FOR_EACH_VEC_ELT (stmts_to_fix, i, stmt)
+ make_new_ssa_for_def (stmt);
+}
+
/* Find the single immediate use of STMT's LHS, and replace it
with OP. Remove STMT. If STMT's LHS is the same as *DEF,
replace *DEF with OP as well. */
@@ -1181,6 +1227,9 @@ static void
zero_one_operation (tree *def, enum tree_code opcode, tree op)
{
gimple *stmt = SSA_NAME_DEF_STMT (*def);
+ /* PR72835 - Record the stmt chain that has to be updated such that
+ we dont use the same LHS when the values computed are different. */
+ auto_vec<gimple *, 64> stmts_to_fix;
do
{
@@ -1190,8 +1239,12 @@ zero_one_operation (tree *def, enum tree
&& stmt_is_power_of_op (stmt, op))
{
if (decrement_power (stmt) == 1)
- propagate_op_to_single_use (op, stmt, def);
- return;
+ {
+ if (stmts_to_fix.length () > 0)
+ stmts_to_fix.pop ();
+ propagate_op_to_single_use (op, stmt, def);
+ }
+ break;
}
name = gimple_assign_rhs1 (stmt);
@@ -1205,8 +1258,10 @@ zero_one_operation (tree *def, enum tree
{
if (name == op)
name = gimple_assign_rhs2 (stmt);
+ if (stmts_to_fix.length () > 0)
+ stmts_to_fix.pop ();
propagate_op_to_single_use (name, stmt, def);
- return;
+ break;
}
/* We might have a multiply of two __builtin_pow* calls, and
@@ -1221,7 +1276,9 @@ zero_one_operation (tree *def, enum tree
{
if (decrement_power (stmt2) == 1)
propagate_op_to_single_use (op, stmt2, def);
- return;
+ else
+ stmts_to_fix.safe_push (stmt2);
+ break;
}
}
@@ -1229,8 +1286,12 @@ zero_one_operation (tree *def, enum tree
gcc_assert (name != op
&& TREE_CODE (name) == SSA_NAME);
stmt = SSA_NAME_DEF_STMT (name);
+ stmts_to_fix.safe_push (stmt);
}
while (1);
+
+ if (stmts_to_fix.length () > 0)
+ make_new_ssa_for_all_defs (def, op, stmts_to_fix);
}
/* Returns true if statement S1 dominates statement S2. Like
--- gcc/testsuite/gcc.dg/tree-ssa/pr72835.c (revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr72835.c (revision 240299)
@@ -0,0 +1,37 @@
+/* PR tree-optimization/72835. */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target int32plus } */
+
+struct struct_1 {
+ unsigned int m1 : 6 ;
+ unsigned int m2 : 24 ;
+ unsigned int m3 : 6 ;
+};
+
+unsigned short var_32 = 0x2d10;
+
+struct struct_1 s1;
+
+void init ()
+{
+ s1.m1 = 4;
+ s1.m2 = 0x7ca4b8;
+ s1.m3 = 24;
+}
+
+void foo ()
+{
+ unsigned int c
+ = ((unsigned int) s1.m2) * (-((unsigned int) s1.m3))
+ + (var_32) * (-((unsigned int) (s1.m1)));
+ if (c != 4098873984)
+ __builtin_abort ();
+}
+
+int main ()
+{
+ init ();
+ foo ();
+ return 0;
+}
[-- Attachment #3: r240505 --]
[-- Type: text/plain, Size: 1601 bytes --]
2016-12-09 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
2016-09-26 Kugan Vivekanandarajah <kuganv@linaro.org>
PR middle-end/77719
* tree-ssa-reassoc.c (make_new_ssa_for_def): Use gimple_get_lhs to get lhs
instead of gimple_assign_lhs as stmt can be builtins too.
* gfortran.dg/pr77719.f90: New test.
--- gcc/tree-ssa-reassoc.c (revision 240504)
+++ gcc/tree-ssa-reassoc.c (revision 240505)
@@ -1158,7 +1158,7 @@ make_new_ssa_for_def (gimple *stmt)
use_operand_p use;
imm_use_iterator iter;
tree new_lhs;
- tree lhs = gimple_assign_lhs (stmt);
+ tree lhs = gimple_get_lhs (stmt);
new_lhs = make_ssa_name (TREE_TYPE (lhs));
gimple_set_lhs (stmt, new_lhs);
--- gcc/testsuite/gfortran.dg/pr77719.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/pr77719.f90 (revision 240505)
@@ -0,0 +1,26 @@
+! PR middle-end/77719
+! { dg-do compile }
+! { dg-options "-O3 -ffast-math" }
+
+SUBROUTINE urep_egr(erep,derep,surr)
+ INTEGER, PARAMETER :: dp=8
+ REAL(dp), INTENT(inout) :: erep, derep(3)
+ REAL(dp), INTENT(in) :: surr(2)
+ REAL(dp) :: de_z, rz
+ INTEGER :: isp,spdim,jsp,nsp
+ IF (n_urpoly > 0) THEN
+ IF (r < spxr(1,1)) THEN
+ ispg: DO isp = 1,spdim ! condition ca)
+ IF (isp /= spdim) THEN
+ nsp = 5 ! condition cb
+ DO jsp = 0,nsp
+ IF( jsp <= 3 ) THEN
+ ELSE
+ erep = erep + surr(jsp-3)*rz**(jsp)
+ ENDIF
+ END DO
+ END IF
+ END DO ispg
+ END IF
+ END IF
+END SUBROUTINE urep_egr
[-- Attachment #4: r243476 --]
[-- Type: text/plain, Size: 5285 bytes --]
2016-12-09 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
2016-12-09 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/78726
* tree-ssa-reassoc.c (make_new_ssa_for_def): Add OPCODE and OP
argument. For lhs uses in debug stmts, don't replace lhs with
new_lhs, but with a debug temp set to new_lhs opcode op.
(make_new_ssa_for_all_defs): Add OPCODE argument, pass OPCODE and
OP down to make_new_ssa_for_def.
(zero_one_operation): Call make_new_ssa_for_all_defs even when
stmts_to_fix is empty, if *def has not changed yet. Pass
OPCODE to make_new_ssa_for_all_defs.
* gcc.c-torture/execute/pr78726.c: New test.
* gcc.dg/guality/pr78726.c: New test.
--- gcc/tree-ssa-reassoc.c (revision 243475)
+++ gcc/tree-ssa-reassoc.c (revision 243476)
@@ -1147,12 +1147,12 @@ decrement_power (gimple *stmt)
SSA. Also return the new SSA. */
static tree
-make_new_ssa_for_def (gimple *stmt)
+make_new_ssa_for_def (gimple *stmt, enum tree_code opcode, tree op)
{
gimple *use_stmt;
use_operand_p use;
imm_use_iterator iter;
- tree new_lhs;
+ tree new_lhs, new_debug_lhs = NULL_TREE;
tree lhs = gimple_get_lhs (stmt);
new_lhs = make_ssa_name (TREE_TYPE (lhs));
@@ -1161,8 +1161,28 @@ make_new_ssa_for_def (gimple *stmt)
/* Also need to update GIMPLE_DEBUGs. */
FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
{
+ tree repl = new_lhs;
+ if (is_gimple_debug (use_stmt))
+ {
+ if (new_debug_lhs == NULL_TREE)
+ {
+ new_debug_lhs = make_node (DEBUG_EXPR_DECL);
+ gdebug *def_temp
+ = gimple_build_debug_bind (new_debug_lhs,
+ build2 (opcode, TREE_TYPE (lhs),
+ new_lhs, op),
+ stmt);
+ DECL_ARTIFICIAL (new_debug_lhs) = 1;
+ TREE_TYPE (new_debug_lhs) = TREE_TYPE (lhs);
+ DECL_MODE (new_debug_lhs) = TYPE_MODE (TREE_TYPE (lhs));
+ gimple_set_uid (def_temp, gimple_uid (stmt));
+ gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+ gsi_insert_after (&gsi, def_temp, GSI_SAME_STMT);
+ }
+ repl = new_debug_lhs;
+ }
FOR_EACH_IMM_USE_ON_STMT (use, iter)
- SET_USE (use, new_lhs);
+ SET_USE (use, repl);
update_stmt (use_stmt);
}
return new_lhs;
@@ -1173,7 +1193,7 @@ make_new_ssa_for_def (gimple *stmt)
if *DEF is not OP. */
static void
-make_new_ssa_for_all_defs (tree *def, tree op,
+make_new_ssa_for_all_defs (tree *def, enum tree_code opcode, tree op,
vec<gimple *> &stmts_to_fix)
{
unsigned i;
@@ -1183,10 +1203,10 @@ make_new_ssa_for_all_defs (tree *def, tr
&& TREE_CODE (*def) == SSA_NAME
&& (stmt = SSA_NAME_DEF_STMT (*def))
&& gimple_code (stmt) != GIMPLE_NOP)
- *def = make_new_ssa_for_def (stmt);
+ *def = make_new_ssa_for_def (stmt, opcode, op);
FOR_EACH_VEC_ELT (stmts_to_fix, i, stmt)
- make_new_ssa_for_def (stmt);
+ make_new_ssa_for_def (stmt, opcode, op);
}
/* Find the single immediate use of STMT's LHS, and replace it
@@ -1226,6 +1246,7 @@ propagate_op_to_single_use (tree op, gim
static void
zero_one_operation (tree *def, enum tree_code opcode, tree op)
{
+ tree orig_def = *def;
gimple *stmt = SSA_NAME_DEF_STMT (*def);
/* PR72835 - Record the stmt chain that has to be updated such that
we dont use the same LHS when the values computed are different. */
@@ -1290,8 +1311,8 @@ zero_one_operation (tree *def, enum tree
}
while (1);
- if (stmts_to_fix.length () > 0)
- make_new_ssa_for_all_defs (def, op, stmts_to_fix);
+ if (stmts_to_fix.length () > 0 || *def == orig_def)
+ make_new_ssa_for_all_defs (def, opcode, op, stmts_to_fix);
}
/* Returns true if statement S1 dominates statement S2. Like
--- gcc/testsuite/gcc.c-torture/execute/pr78726.c (revision 0)
+++ gcc/testsuite/gcc.c-torture/execute/pr78726.c (revision 243476)
@@ -0,0 +1,23 @@
+/* PR tree-optimization/78726 */
+
+unsigned char b = 36, c = 173;
+unsigned int d;
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+ unsigned a = ~b;
+ d = a * c * c + 1023094746U * a;
+}
+
+int
+main ()
+{
+ if (__SIZEOF_INT__ != 4 || __CHAR_BIT__ != 8)
+ return 0;
+ asm volatile ("" : : "g" (&b), "g" (&c) : "memory");
+ foo ();
+ if (d != 799092689U)
+ __builtin_abort ();
+ return 0;
+}
--- gcc/testsuite/gcc.dg/guality/pr78726.c (revision 0)
+++ gcc/testsuite/gcc.dg/guality/pr78726.c (revision 243476)
@@ -0,0 +1,30 @@
+/* PR tree-optimization/78726 */
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+#include "../nop.h"
+
+unsigned char b = 36, c = 173;
+unsigned int d;
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+ unsigned a = ~b;
+ unsigned d1 = a * c; /* { dg-final { gdb-test 21 "d1" "~36U * 173" } } */
+ unsigned d2 = d1 * c; /* { dg-final { gdb-test 21 "d2" "~36U * 173 * 173" } } */
+ unsigned d3 = 1023094746 * a; /* { dg-final { gdb-test 21 "d3" "~36U * 1023094746" } } */
+ d = d2 + d3;
+ unsigned d4 = d1 * 2; /* { dg-final { gdb-test 21 "d4" "~36U * 173 * 2" } } */
+ unsigned d5 = d2 * 2; /* { dg-final { gdb-test 21 "d5" "~36U * 173 * 173 * 2" } } */
+ unsigned d6 = d3 * 2; /* { dg-final { gdb-test 21 "d6" "~36U * 1023094746 * 2" } } */
+ asm (NOP : : : "memory");
+}
+
+int
+main ()
+{
+ asm volatile ("" : : "g" (&b), "g" (&c) : "memory");
+ foo ();
+ return 0;
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-09 12:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-09 12:50 3 further backports to 6.3 Jakub Jelinek
2016-12-09 12:57 ` 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).