diff --git a/gcc/testsuite/gcc.dg/lto/pr109778_0.c b/gcc/testsuite/gcc.dg/lto/pr109778_0.c
new file mode 100644
index 0000000000000000000000000000000000000000..3c6e1b8f7b7d05a935dadf7d3da61ab2d9f4bfe9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr109778_0.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/109778 */
+/* { dg-lto-do run } */
+/* { dg-lto-options { "-O2 -flto" } } */
+/* { dg-require-effective-target int32 } */
+
+int bar (int);
+
+__attribute__((noipa)) int
+foo (int x)
+{
+  x = bar (x);
+  x = (x << 16) | (int) ((unsigned) x >> 16);
+  return x & 0x10000000;
+}
+
+int
+main ()
+{
+  if (foo (0) || foo (-1))
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr109778_1.c b/gcc/testsuite/gcc.dg/lto/pr109778_1.c
new file mode 100644
index 0000000000000000000000000000000000000000..d18a7209983e109b978cda42b3dab6618e8fd712
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr109778_1.c
@@ -0,0 +1,7 @@
+int
+bar (int x)
+{
+  x &= 0x22222222;
+  x |= (int) 0xf1234567U;
+  return x;
+}