diff mbox

Look into unnecessary conversion when checking mult_op in get_shiftadd_cost

Message ID 000c01d0e532$823066c0$86913440$@arm.com
State New
Headers show

Commit Message

Bin Cheng Sept. 2, 2015, 3:50 a.m. UTC
Hi,
When calling get_shiftadd_cost, the mult_op is stripped at caller places.
We should look into unnecessary conversion in op1 before checking equality,
otherwise it computes wrong shiftadd cost.  This patch picks this small
issue up.

Bootstrap and test on x86_64 and aarch64 along with other patches.  Is it
OK?

Thanks,
bin

2015-08-31  Bin Cheng  <bin.cheng@arm.com>

	* tree-ssa-loop-ivopts.c (get_shiftadd_cost): Look into
	unnecessary type conversion for OP1.

Comments

Richard Biener Sept. 2, 2015, 12:32 p.m. UTC | #1
On Wed, Sep 2, 2015 at 5:50 AM, Bin Cheng <bin.cheng@arm.com> wrote:
> Hi,
> When calling get_shiftadd_cost, the mult_op is stripped at caller places.
> We should look into unnecessary conversion in op1 before checking equality,
> otherwise it computes wrong shiftadd cost.  This patch picks this small
> issue up.
>
> Bootstrap and test on x86_64 and aarch64 along with other patches.  Is it
> OK?

Just do STRIP_NOPS (op1) unconditionally?  Thus

  STRIP_NOPS (op1);
  mult_in_op1 = operand_equal_p (op1, mult, 0);

ok with that change.

Thanks,
Richard.

> Thanks,
> bin
>
> 2015-08-31  Bin Cheng  <bin.cheng@arm.com>
>
>         * tree-ssa-loop-ivopts.c (get_shiftadd_cost): Look into
>         unnecessary type conversion for OP1.
Bin.Cheng Sept. 15, 2015, 5:53 a.m. UTC | #2
On Wed, Sep 2, 2015 at 8:32 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Wed, Sep 2, 2015 at 5:50 AM, Bin Cheng <bin.cheng@arm.com> wrote:
>> Hi,
>> When calling get_shiftadd_cost, the mult_op is stripped at caller places.
>> We should look into unnecessary conversion in op1 before checking equality,
>> otherwise it computes wrong shiftadd cost.  This patch picks this small
>> issue up.
>>
>> Bootstrap and test on x86_64 and aarch64 along with other patches.  Is it
>> OK?
>
> Just do STRIP_NOPS (op1) unconditionally?  Thus
>
>   STRIP_NOPS (op1);
>   mult_in_op1 = operand_equal_p (op1, mult, 0);
>
> ok with that change.
Patch committed as suggested.

Thanks,
bin
diff mbox

Patch

Index: gcc/tree-ssa-loop-ivopts.c
===================================================================
--- gcc/tree-ssa-loop-ivopts.c	(revision 227163)
+++ gcc/tree-ssa-loop-ivopts.c	(working copy)
@@ -3884,12 +4038,14 @@  get_shiftadd_cost (tree expr, machine_mode mode, c
   int m = exact_log2 (int_cst_value (cst));
   int maxm = MIN (BITS_PER_WORD, GET_MODE_BITSIZE (mode));
   int as_cost, sa_cost;
-  bool mult_in_op1;
+  bool mult_in_op1 = false;
 
   if (!(m >= 0 && m < maxm))
     return false;
 
-  mult_in_op1 = operand_equal_p (op1, mult, 0);
+  if (operand_equal_p (op1, mult, 0)
+      || operand_equal_p (STRIP_NOPS (op1), mult, 0))
+    mult_in_op1 = true;
 
   as_cost = add_cost (speed, mode) + shift_cost (speed, mode, m);