In a similar way find_split_point handles `a+b*C`, this adds
the split point for `~a & b`.  This allows for better instruction
selection when the target has this instruction (aarch64, arm and x86_64
are examples which have this).

Built and tested for aarch64-linux-gnu.

        PR rtl-optmization/111949

gcc/ChangeLog:

        * combine.cc (find_split_point): Add a split point
        for `(and (not X) Y)` if not in the outer set already.

gcc/testsuite/ChangeLog:

        * gcc.target/aarch64/bic-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
---
 gcc/combine.cc                           |  6 ++++
 gcc/testsuite/gcc.target/aarch64/bic-1.c | 40 ++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/bic-1.c

diff --git a/gcc/combine.cc b/gcc/combine.cc
index a2d4387cebe..d136ee9b24a 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -5257,6 +5257,12 @@ find_split_point (rtx *loc, rtx_insn *insn, bool set_src)
          SUBST (XEXP (x, 0), XEXP (x, 1));
          SUBST (XEXP (x, 1), tem);
        }
+      /* Many targets have a `(and (not X) Y)` and/or `(ior (not X) Y)` 
instructions.
+        Split at that insns.  However if this is
+        the SET_SRC, we likely do not have such an instruction and it's
+        worthless to try this split.  */
+      if (!set_src && GET_CODE (XEXP (x, 0)) == NOT)
+       return loc;
       break;
 
     case PLUS:
diff --git a/gcc/testsuite/gcc.target/aarch64/bic-1.c 
b/gcc/testsuite/gcc.target/aarch64/bic-1.c
new file mode 100644
index 00000000000..65e1514755f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/bic-1.c
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/* PR rtl-optmization/111949 */
+
+/*
+**func1:
+**     bic     w([0-9]+), w0, w1
+**     and     w0, w\1, 1
+**      ret
+*/
+
+unsigned func1(unsigned a, bool b)
+{
+        int c = a & b;
+        return (c ^ a)&1;
+}
+
+/*
+**func2:
+**     bic     w([0-9]+), w1, w0
+**     and     w0, w\1, 255
+**      ret
+*/
+unsigned func2(bool a, bool b)
+{
+  return ~a & b;
+}
+
+/*
+**func3:
+**     bic     w([0-9]+), w1, w0
+**     and     w0, w\1, 1
+**      ret
+*/
+bool func3(bool a, unsigned char b)
+{
+  return !a & b;
+}
-- 
2.43.0

Reply via email to