From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125004 invoked by alias); 9 Dec 2016 12:50:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 124935 invoked by uid 89); 9 Dec 2016 12:50:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=STMT, INTENT, SUBROUTINE, jsp X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Dec 2016 12:50:19 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F12C61963; Fri, 9 Dec 2016 12:50:18 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-100.brq.redhat.com [10.40.204.100]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB9CoGvE001732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 9 Dec 2016 07:50:17 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id uB9CoF93027568; Fri, 9 Dec 2016 13:50:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id uB9CoEaL027567; Fri, 9 Dec 2016 13:50:14 +0100 Date: Fri, 09 Dec 2016 12:50:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: 3 further backports to 6.3 Message-ID: <20161209125014.GB3541@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0NUq3YI6/rBc6tSL" Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00767.txt.bz2 --0NUq3YI6/rBc6tSL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 277 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 --0NUq3YI6/rBc6tSL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=r240299 Content-length: 4335 2016-12-09 Jakub Jelinek Backported from mainline 2016-09-21 Kugan Vivekanandarajah 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 &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 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; +} --0NUq3YI6/rBc6tSL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=r240505 Content-length: 1601 2016-12-09 Jakub Jelinek Backported from mainline 2016-09-26 Kugan Vivekanandarajah 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 --0NUq3YI6/rBc6tSL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=r243476 Content-length: 5285 2016-12-09 Jakub Jelinek Backported from mainline 2016-12-09 Jakub Jelinek 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 &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; +} --0NUq3YI6/rBc6tSL--