* move a * (1 << b) -> a << b pattern from fold-const.c to match.pd
@ 2015-07-06 20:29 Prathamesh Kulkarni
2015-07-06 20:59 ` Jeff Law
2015-07-07 5:48 ` Marc Glisse
0 siblings, 2 replies; 6+ messages in thread
From: Prathamesh Kulkarni @ 2015-07-06 20:29 UTC (permalink / raw)
To: Richard Biener, gcc Patches
[-- Attachment #1: Type: text/plain, Size: 180 bytes --]
Hi,
The attached patch moves pattern a * (1 << b) -> a << b.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
OK for trunk if testing passes ?
Thank you,
Prathamesh
[-- Attachment #2: ChangeLog.txt --]
[-- Type: text/plain, Size: 252 bytes --]
2015-07-06 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
* fold-const.c (fold_binary_loc): Remove pattern a * 1 << b -> a << b.
* match.pd (a * 1 << b -> a << b): New pattern.
testsuite/
* gcc.dg/tree-ssa/fold-shiftmult.c: New test-case.
[-- Attachment #3: patch.txt --]
[-- Type: text/plain, Size: 1951 bytes --]
Index: fold-const.c
===================================================================
--- fold-const.c (revision 225473)
+++ fold-const.c (working copy)
@@ -10175,16 +10175,6 @@
negate_expr (arg0)),
tem);
- /* (a * (1 << b)) is (a << b) */
- if (TREE_CODE (arg1) == LSHIFT_EXPR
- && integer_onep (TREE_OPERAND (arg1, 0)))
- return fold_build2_loc (loc, LSHIFT_EXPR, type, op0,
- TREE_OPERAND (arg1, 1));
- if (TREE_CODE (arg0) == LSHIFT_EXPR
- && integer_onep (TREE_OPERAND (arg0, 0)))
- return fold_build2_loc (loc, LSHIFT_EXPR, type, op1,
- TREE_OPERAND (arg0, 1));
-
/* (A + A) * C -> A * 2 * C */
if (TREE_CODE (arg0) == PLUS_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
Index: match.pd
===================================================================
--- match.pd (revision 225473)
+++ match.pd (working copy)
@@ -854,6 +854,12 @@
&& tree_expr_nonnegative_p (@1))
@0))
+/* a * (1 << b) -> a << b */
+(simplify
+ (mult:c @a (lshift integer_onep @b))
+ (if (!FLOAT_TYPE_P (type))
+ (lshift @a @b)))
+
(for shiftrotate (lrotate rrotate lshift rshift)
(simplify
(shiftrotate @0 integer_zerop)
Index: testsuite/gcc.dg/tree-ssa/fold-shiftmult.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/fold-shiftmult.c (revision 0)
+++ testsuite/gcc.dg/tree-ssa/fold-shiftmult.c (working copy)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop-details" } */
+
+int f1(int a, int b)
+{
+ int t1 = 1 << b;
+ int f1_val = a * t1;
+ return f1_val;
+}
+/* { dg-final { scan-tree-dump "gimple_simplified to f1_val_\\d\+ = a_\\d\+\\(D\\) << b_\\d\+\\(D\\)" "forwprop1" } } */
+
+int f2(int a, int b)
+{
+ int t1 = 1 << b;
+ int f2_val = t1 * a;
+ return f2_val;
+}
+
+/* { dg-final { scan-tree-dump "gimple_simplified to f2_val_\\d\+ = a_\\d\+\\(D\\) << b_\\d\+\\(D\\)" "forwprop1" } } */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: move a * (1 << b) -> a << b pattern from fold-const.c to match.pd
2015-07-06 20:29 move a * (1 << b) -> a << b pattern from fold-const.c to match.pd Prathamesh Kulkarni
@ 2015-07-06 20:59 ` Jeff Law
2015-07-07 5:48 ` Marc Glisse
1 sibling, 0 replies; 6+ messages in thread
From: Jeff Law @ 2015-07-06 20:59 UTC (permalink / raw)
To: Prathamesh Kulkarni, Richard Biener, gcc Patches
On 07/06/2015 02:28 PM, Prathamesh Kulkarni wrote:
> Hi,
> The attached patch moves pattern a * (1 << b) -> a << b.
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> OK for trunk if testing passes ?
>
> Thank you,
> Prathamesh
>
>
> ChangeLog.txt
>
>
> 2015-07-06 Prathamesh Kulkarni<prathamesh.kulkarni@linaro.org>
>
> * fold-const.c (fold_binary_loc): Remove pattern a * 1 << b -> a << b.
> * match.pd (a * 1 << b -> a << b): New pattern.
>
> testsuite/
> * gcc.dg/tree-ssa/fold-shiftmult.c: New test-case.
OK assuming testing passes.
jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: move a * (1 << b) -> a << b pattern from fold-const.c to match.pd
2015-07-06 20:29 move a * (1 << b) -> a << b pattern from fold-const.c to match.pd Prathamesh Kulkarni
2015-07-06 20:59 ` Jeff Law
@ 2015-07-07 5:48 ` Marc Glisse
2015-07-09 9:34 ` Marek Polacek
1 sibling, 1 reply; 6+ messages in thread
From: Marc Glisse @ 2015-07-07 5:48 UTC (permalink / raw)
To: Prathamesh Kulkarni; +Cc: Richard Biener, gcc Patches
On Tue, 7 Jul 2015, Prathamesh Kulkarni wrote:
> +/* a * (1 << b) -> a << b */
> +(simplify
> + (mult:c @a (lshift integer_onep @b))
> + (if (!FLOAT_TYPE_P (type))
> + (lshift @a @b)))
The test FLOAT_TYPE_P seems unnecessary, 'type' is (up to a useless
conversion) the result of a shift, so integer, fixed-point or vector. Its
lhs is integer_onep, which rules out fixed-point.
(I think it is the first pattern using @letter and not @number)
--
Marc Glisse
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: move a * (1 << b) -> a << b pattern from fold-const.c to match.pd
2015-07-07 5:48 ` Marc Glisse
@ 2015-07-09 9:34 ` Marek Polacek
2015-07-09 10:02 ` Richard Biener
0 siblings, 1 reply; 6+ messages in thread
From: Marek Polacek @ 2015-07-09 9:34 UTC (permalink / raw)
To: Marc Glisse; +Cc: Prathamesh Kulkarni, Richard Biener, gcc Patches
On Tue, Jul 07, 2015 at 07:47:50AM +0200, Marc Glisse wrote:
> On Tue, 7 Jul 2015, Prathamesh Kulkarni wrote:
>
> >+/* a * (1 << b) -> a << b */
> >+(simplify
> >+ (mult:c @a (lshift integer_onep @b))
> >+ (if (!FLOAT_TYPE_P (type))
> >+ (lshift @a @b)))
Just a nit: the last line is wrongly formatted.
> The test FLOAT_TYPE_P seems unnecessary, 'type' is (up to a useless
> conversion) the result of a shift, so integer, fixed-point or vector. Its
> lhs is integer_onep, which rules out fixed-point.
Right.
> (I think it is the first pattern using @letter and not @number)
Yea, I think we should be consistent and use @0 and @1 here.
Marek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: move a * (1 << b) -> a << b pattern from fold-const.c to match.pd
2015-07-09 9:34 ` Marek Polacek
@ 2015-07-09 10:02 ` Richard Biener
2015-07-09 10:35 ` Marek Polacek
0 siblings, 1 reply; 6+ messages in thread
From: Richard Biener @ 2015-07-09 10:02 UTC (permalink / raw)
To: Marek Polacek; +Cc: Marc Glisse, Prathamesh Kulkarni, gcc Patches
On Thu, 9 Jul 2015, Marek Polacek wrote:
> On Tue, Jul 07, 2015 at 07:47:50AM +0200, Marc Glisse wrote:
> > On Tue, 7 Jul 2015, Prathamesh Kulkarni wrote:
> >
> > >+/* a * (1 << b) -> a << b */
> > >+(simplify
> > >+ (mult:c @a (lshift integer_onep @b))
> > >+ (if (!FLOAT_TYPE_P (type))
> > >+ (lshift @a @b)))
>
> Just a nit: the last line is wrongly formatted.
>
> > The test FLOAT_TYPE_P seems unnecessary, 'type' is (up to a useless
> > conversion) the result of a shift, so integer, fixed-point or vector. Its
> > lhs is integer_onep, which rules out fixed-point.
>
> Right.
>
> > (I think it is the first pattern using @letter and not @number)
>
> Yea, I think we should be consistent and use @0 and @1 here.
I've added support for non-digit names to allow more descriptive
patterns. Like when we have
/* Fold (X << C1) & C2 into (X << C1) & (C2 | ((1 << C1) - 1))
(X >> C1) & C2 into (X >> C1) & (C2 | ~((type) -1 >> C1))
if the new mask might be further optimized. */
(for shift (lshift rshift)
(simplify
(bit_and (convert?@4 (shift@5 (convert1?@3 @0) INTEGER_CST@1))
INTEGER_CST@2)
using @andop2 instead of @2 and @shift instead of @5 (etc.) might
make the following code easier to follow.
That everything uses digits right now is historic mostly (and
my habit of using digits just because I got used to it).
But yes, with @a, @b vs. @0, @1 we should standardize on something
(digits).
Richard.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: move a * (1 << b) -> a << b pattern from fold-const.c to match.pd
2015-07-09 10:02 ` Richard Biener
@ 2015-07-09 10:35 ` Marek Polacek
0 siblings, 0 replies; 6+ messages in thread
From: Marek Polacek @ 2015-07-09 10:35 UTC (permalink / raw)
To: Richard Biener; +Cc: Marc Glisse, Prathamesh Kulkarni, gcc Patches
On Thu, Jul 09, 2015 at 12:02:19PM +0200, Richard Biener wrote:
> I've added support for non-digit names to allow more descriptive
> patterns. Like when we have
>
> /* Fold (X << C1) & C2 into (X << C1) & (C2 | ((1 << C1) - 1))
> (X >> C1) & C2 into (X >> C1) & (C2 | ~((type) -1 >> C1))
> if the new mask might be further optimized. */
> (for shift (lshift rshift)
> (simplify
> (bit_and (convert?@4 (shift@5 (convert1?@3 @0) INTEGER_CST@1))
> INTEGER_CST@2)
>
> using @andop2 instead of @2 and @shift instead of @5 (etc.) might
> make the following code easier to follow.
All right, that makes sense.
> That everything uses digits right now is historic mostly (and
> my habit of using digits just because I got used to it).
>
> But yes, with @a, @b vs. @0, @1 we should standardize on something
> (digits).
>
> Richard.
Marek
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-07-09 10:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06 20:29 move a * (1 << b) -> a << b pattern from fold-const.c to match.pd Prathamesh Kulkarni
2015-07-06 20:59 ` Jeff Law
2015-07-07 5:48 ` Marc Glisse
2015-07-09 9:34 ` Marek Polacek
2015-07-09 10:02 ` Richard Biener
2015-07-09 10:35 ` Marek Polacek
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).