diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 0b326d497b47e1909d8cb2e136952253336bc333..af9087508ac6b96f0b35a4e2b68b65b748acd5fc 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -949,8 +949,8 @@
 
 (define_expand "tbranch_<code><mode>3"
   [(set (pc) (if_then_else
-              (EQL (match_operand:ALLI 0 "register_operand")
-                   (match_operand 1 "aarch64_simd_shift_imm_<mode>"))
+              (EQL (match_operand:SHORT 0 "register_operand")
+                   (match_operand 1 "const0_operand"))
               (label_ref (match_operand 2 ""))
               (pc)))]
   ""
diff --git a/gcc/testsuite/gcc.target/aarch64/tbz_2.c b/gcc/testsuite/gcc.target/aarch64/tbz_2.c
new file mode 100644
index 0000000000000000000000000000000000000000..ec128b58f35276a7c5452685a65c73f95f2d5f9a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tbz_2.c
@@ -0,0 +1,130 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -std=c99  -fno-unwind-tables -fno-asynchronous-unwind-tables" } */
+/* { dg-final { check-function-bodies "**" "" "" { target { le } } } } */
+
+#include <stdbool.h>
+
+void h(void);
+
+/*
+** g1:
+** 	cbnz	w0, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g1(int x)
+{
+  if (__builtin_expect (x, 0))
+    h ();
+}
+
+/* 
+** g2:
+** 	tbnz	x0, 0, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g2(int x)
+{
+  if (__builtin_expect (x & 1, 0))
+    h ();
+}
+
+/* 
+** g3:
+** 	tbnz	x0, 3, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g3(int x)
+{
+  if (__builtin_expect (x & 8, 0))
+    h ();
+}
+
+/* 
+** g4:
+** 	tbnz	w0, #31, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g4(int x)
+{
+  if (__builtin_expect (x & (1 << 31), 0))
+    h ();
+}
+
+/* 
+** g5:
+** 	tst	w0, 255
+** 	bne	.L[0-9]+
+** 	ret
+** 	...
+*/
+void g5(char x)
+{
+  if (__builtin_expect (x, 0))
+    h ();
+}
+
+/* 
+** g6:
+** 	tbnz	w0, 0, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g6(char x)
+{
+  if (__builtin_expect (x & 1, 0))
+    h ();
+}
+
+/* 
+** g7:
+** 	tst	w0, 3
+** 	bne	.L[0-9]+
+** 	ret
+** 	...
+*/
+void g7(char x)
+{
+  if (__builtin_expect (x & 3, 0))
+    h ();
+}
+
+/* 
+** g8:
+** 	tbnz	w0, 7, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g8(char x)
+{
+  if (__builtin_expect (x & (1 << 7), 0))
+    h ();
+}
+
+/* 
+** g9:
+** 	tbnz	w0, 0, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g9(bool x)
+{
+  if (__builtin_expect (x, 0))
+    h ();
+}
+
+/* 
+** g10:
+** 	tbnz	w0, 0, .L[0-9]+
+** 	ret
+** 	...
+*/
+void g10(bool x)
+{
+  if (__builtin_expect (x & 1, 0))
+    h ();
+}
+
diff --git a/gcc/testsuite/gcc.target/aarch64/tbz_3.c b/gcc/testsuite/gcc.target/aarch64/tbz_3.c
new file mode 100644
index 0000000000000000000000000000000000000000..74f758d33e2273b9d4fdf118c2ee5072eef76f8e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tbz_3.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void g(int);
+
+void
+f (unsigned int x, _Bool y)
+{
+  for (int i = 0; i < 100; ++i)
+    {
+      if ((x >> 31) | y)
+	g (1);
+      for (int j = 0; j < 100; ++j)
+	g (2);
+    }
+}
+
+/* { dg-final { scan-assembler-times {and\t} 1 } } */