[combine][v2] Canonicalise (r + r) to (r << 1) to aid recognition
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Tue, 5 Jan 2016 16:06:06 +0000 (16:06 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Tue, 5 Jan 2016 16:06:06 +0000 (16:06 +0000)
PR rtl-optimization/68651
* combine.c (combine_simplify_rtx): Canonicalize x + x into
x << 1.

* gcc.target/aarch64/pr68651_1.c: New test.

From-SVN: r232077

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/pr68651_1.c [new file with mode: 0644]

index ff297bca9e3f725f09574e0a9f82bbdcdf763a4a..98d6fefe93d2d434e80a3308015568dc73f833f2 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-05  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68651
+       * combine.c (combine_simplify_rtx): Canonicalize x + x into
+       x << 1.
+
 2016-01-05  Nathan Sidwell  <nathan@acm.org>
 
        * alias.c (compare_base_decls): Use symtab_node::get.
index fd384881cd637381de1a02216847d1aec7f3eb3d..d088031b853f8b7f407325a071ef02afa18f8751 100644 (file)
@@ -5895,6 +5895,13 @@ combine_simplify_rtx (rtx x, machine_mode op0_mode, int in_dest,
                          || XEXP (temp, 1) != XEXP (x, 0)))))
            return temp;
        }
+
+      /* Canonicalize x + x into x << 1.  */
+      if (GET_MODE_CLASS (mode) == MODE_INT
+         && rtx_equal_p (XEXP (x, 0), XEXP (x, 1))
+         && !side_effects_p (XEXP (x, 0)))
+       return simplify_gen_binary (ASHIFT, mode, XEXP (x, 0), const1_rtx);
+
       break;
 
     case MINUS:
index 9ff53ae6c1196699d20f4557f992cb8a22eafe04..4ab864ef371f7b73b7d08eed2b07b261a8c25ead 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-05  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       PR rtl-optimization/68651
+       * gcc.target/aarch64/pr68651_1.c: New test.
+
 2016-01-05  David Malcolm  <dmalcolm@redhat.com>
 
        PR c/69122
diff --git a/gcc/testsuite/gcc.target/aarch64/pr68651_1.c b/gcc/testsuite/gcc.target/aarch64/pr68651_1.c
new file mode 100644 (file)
index 0000000..ef9456f
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=cortex-a53" } */
+
+int
+foo (int x)
+{
+  return (x * 2) & 65535;
+}
+/* { dg-final { scan-assembler "ubfiz\tw\[0-9\]*, w\[0-9\]*.*\n" } } */
+
+int
+bar (int x, int y)
+{
+  return (x * 2) | y;
+}
+/* { dg-final { scan-assembler "orr\tw\[0-9\]*, w\[0-9\]*, w\[0-9\]*, lsl 1.*\n" } } */