From: Kugan Vivekanandarajah Date: Tue, 2 Jun 2015 22:53:15 +0000 (+0000) Subject: re PR target/65768 (sub-optimimal code for constant Uses in loop) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=32e0a7d983cd3076bbdff448e583773ee4081a37;p=gcc.git re PR target/65768 (sub-optimimal code for constant Uses in loop) gcc/ChangeLog: 2015-06-03 Kugan Vivekanandarajah Zhenqiang Chen PR target/65768 * cprop.c (try_replace_reg): Check cost of constants before propagating. gcc/testsuite/ChangeLog: 2015-06-03 Kugan Vivekanandarajah PR target/65768 * gcc.target/arm/maskdata.c: Remove -fno-gcse. Co-Authored-By: Zhenqiang Chen From-SVN: r224048 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fc87c186148..d1e55c74e1f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-06-03 Kugan Vivekanandarajah + Zhenqiang Chen + + PR target/65768 + * cprop.c (try_replace_reg): Check cost of constants before propagating. + 2015-06-02 Michael Meissner * config/rs6000/rs6000-modes.def (IFmode): Define IFmode to diff --git a/gcc/cprop.c b/gcc/cprop.c index 41ca20124ed..6a756f3fced 100644 --- a/gcc/cprop.c +++ b/gcc/cprop.c @@ -766,12 +766,37 @@ try_replace_reg (rtx from, rtx to, rtx_insn *insn) int success = 0; rtx set = single_set (insn); + bool check_rtx_costs = true; + bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)); + int old_cost = set ? set_rtx_cost (set, speed) : 0; + + if ((note != 0 + && REG_NOTE_KIND (note) == REG_EQUAL + && (GET_CODE (XEXP (note, 0)) == CONST + || CONSTANT_P (XEXP (note, 0)))) + || (set && CONSTANT_P (SET_SRC (set)))) + check_rtx_costs = false; + /* Usually we substitute easy stuff, so we won't copy everything. We however need to take care to not duplicate non-trivial CONST expressions. */ to = copy_rtx (to); validate_replace_src_group (from, to, insn); + + /* If TO is a constant, check the cost of the set after propagation + to the cost of the set before the propagation. If the cost is + higher, then do not replace FROM with TO. */ + + if (check_rtx_costs + && CONSTANT_P (to) + && (set_rtx_cost (set, speed) > old_cost)) + { + cancel_changes (0); + return false; + } + + if (num_changes_pending () && apply_change_group ()) success = 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1b3126d4fa6..9175014001d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-06-01 Kugan Vivekanandarajah + + PR target/65768 + * gcc.target/arm/maskdata.c: Remove -fno-gcse. + 2015-06-02 Steven G. Kargl PR fortran/66380 diff --git a/gcc/testsuite/gcc.target/arm/maskdata.c b/gcc/testsuite/gcc.target/arm/maskdata.c index 6d6bb39a265..35d2f060d10 100644 --- a/gcc/testsuite/gcc.target/arm/maskdata.c +++ b/gcc/testsuite/gcc.target/arm/maskdata.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options " -O2 -fno-gcse " } */ +/* { dg-options " -O2" } */ /* { dg-require-effective-target arm_thumb2_ok } */ #define MASK 0xff00ff