===================================================================
@@ -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
===================================================================
@@ -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)
===================================================================
@@ -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" } } */