diff mbox series

set_rtx_cost used wrongly, should be set_src_cost

Message ID 20200414004012.GA5295@bubble.grove.modra.org
State New
Headers show
Series set_rtx_cost used wrongly, should be set_src_cost | expand

Commit Message

Alan Modra April 14, 2020, 12:40 a.m. UTC
I believe set_rtx_cost is meant to handle a SET, not a PLUS as is
passed in these two locations.  Using the proper function for a PLUS
doesn't make a huge difference: the only arg change to rtx_cost of any
consequence is outer_code of SET rather than INSN.  A mode of
word_mode rather than VOIDmode makes no difference at all since the
mode is taken from the PLUS.  An opno of 1 rather than 4 also doesn't
change anything since the only backend that does anything with opno
(besides pass it back to a recursive rtx_cost call) is nios2, and
there "opno == 0" is the only use of opno.

Bootstrapped and regression tested powerpc64le-linux and x86_64-linux.
OK for next stage1?

	* tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Replace
	set_rtx_cost with set_src_cost.
	* tree-switch-conversion.c (bit_test_cluster::emit): Likewise.

Comments

Richard Sandiford April 21, 2020, 12:41 p.m. UTC | #1
Alan Modra via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> I believe set_rtx_cost is meant to handle a SET, not a PLUS as is
> passed in these two locations.  Using the proper function for a PLUS
> doesn't make a huge difference: the only arg change to rtx_cost of any
> consequence is outer_code of SET rather than INSN.  A mode of
> word_mode rather than VOIDmode makes no difference at all since the
> mode is taken from the PLUS.  An opno of 1 rather than 4 also doesn't
> change anything since the only backend that does anything with opno
> (besides pass it back to a recursive rtx_cost call) is nios2, and
> there "opno == 0" is the only use of opno.
>
> Bootstrapped and regression tested powerpc64le-linux and x86_64-linux.
> OK for next stage1?

Yes, thanks.

Richard

>
> 	* tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Replace
> 	set_rtx_cost with set_src_cost.
> 	* tree-switch-conversion.c (bit_test_cluster::emit): Likewise.
>
> diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
> index ec1c033a2cf..af8faf2e6ea 100644
> --- a/gcc/tree-ssa-reassoc.c
> +++ b/gcc/tree-ssa-reassoc.c
> @@ -3208,8 +3208,9 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
>  	      HOST_WIDE_INT m = tree_to_uhwi (lowi);
>  	      rtx reg = gen_raw_REG (word_mode, 10000);
>  	      bool speed_p = optimize_bb_for_speed_p (gimple_bb (stmt));
> -	      cost_diff = set_rtx_cost (gen_rtx_PLUS (word_mode, reg,
> -						      GEN_INT (-m)), speed_p);
> +	      cost_diff = set_src_cost (gen_rtx_PLUS (word_mode, reg,
> +						      GEN_INT (-m)),
> +					word_mode, speed_p);
>  	      rtx r = immed_wide_int_const (mask, word_mode);
>  	      cost_diff += set_src_cost (gen_rtx_AND (word_mode, reg, r),
>  					 word_mode, speed_p);
> diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
> index bf910dd62b5..4b435941d12 100644
> --- a/gcc/tree-switch-conversion.c
> +++ b/gcc/tree-switch-conversion.c
> @@ -1541,8 +1541,9 @@ bit_test_cluster::emit (tree index_expr, tree index_type,
>        HOST_WIDE_INT m = tree_to_uhwi (minval);
>        rtx reg = gen_raw_REG (word_mode, 10000);
>        bool speed_p = optimize_insn_for_speed_p ();
> -      cost_diff = set_rtx_cost (gen_rtx_PLUS (word_mode, reg,
> -					      GEN_INT (-m)), speed_p);
> +      cost_diff = set_src_cost (gen_rtx_PLUS (word_mode, reg,
> +					      GEN_INT (-m)),
> +				word_mode, speed_p);
>        for (i = 0; i < count; i++)
>  	{
>  	  rtx r = immed_wide_int_const (test[i].mask, word_mode);
Li, Pan2 via Gcc-patches May 7, 2020, 6:01 p.m. UTC | #2
On Tue, 2020-04-21 at 13:41 +0100, Richard Sandiford wrote:
> Alan Modra via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> > I believe set_rtx_cost is meant to handle a SET, not a PLUS as is
> > passed in these two locations.  Using the proper function for a PLUS
> > doesn't make a huge difference: the only arg change to rtx_cost of any
> > consequence is outer_code of SET rather than INSN.  A mode of
> > word_mode rather than VOIDmode makes no difference at all since the
> > mode is taken from the PLUS.  An opno of 1 rather than 4 also doesn't
> > change anything since the only backend that does anything with opno
> > (besides pass it back to a recursive rtx_cost call) is nios2, and
> > there "opno == 0" is the only use of opno.
> > 
> > Bootstrapped and regression tested powerpc64le-linux and x86_64-linux.
> > OK for next stage1?
> 
> Yes, thanks.
> 
> Richard
> 
> > 	* tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Replace
> > 	set_rtx_cost with set_src_cost.
> > 	* tree-switch-conversion.c (bit_test_cluster::emit): Likewise.
Pushed to the trunk.

jeff
> >
diff mbox series

Patch

diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index ec1c033a2cf..af8faf2e6ea 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -3208,8 +3208,9 @@  optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
 	      HOST_WIDE_INT m = tree_to_uhwi (lowi);
 	      rtx reg = gen_raw_REG (word_mode, 10000);
 	      bool speed_p = optimize_bb_for_speed_p (gimple_bb (stmt));
-	      cost_diff = set_rtx_cost (gen_rtx_PLUS (word_mode, reg,
-						      GEN_INT (-m)), speed_p);
+	      cost_diff = set_src_cost (gen_rtx_PLUS (word_mode, reg,
+						      GEN_INT (-m)),
+					word_mode, speed_p);
 	      rtx r = immed_wide_int_const (mask, word_mode);
 	      cost_diff += set_src_cost (gen_rtx_AND (word_mode, reg, r),
 					 word_mode, speed_p);
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index bf910dd62b5..4b435941d12 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -1541,8 +1541,9 @@  bit_test_cluster::emit (tree index_expr, tree index_type,
       HOST_WIDE_INT m = tree_to_uhwi (minval);
       rtx reg = gen_raw_REG (word_mode, 10000);
       bool speed_p = optimize_insn_for_speed_p ();
-      cost_diff = set_rtx_cost (gen_rtx_PLUS (word_mode, reg,
-					      GEN_INT (-m)), speed_p);
+      cost_diff = set_src_cost (gen_rtx_PLUS (word_mode, reg,
+					      GEN_INT (-m)),
+				word_mode, speed_p);
       for (i = 0; i < count; i++)
 	{
 	  rtx r = immed_wide_int_const (test[i].mask, word_mode);