13f101
2017-05-30  Jakub Jelinek  <jakub@redhat.com>
13f101
 
13f101
 	Backported from mainline
13f101
	2016-11-16  Jakub Jelinek  <jakub@redhat.com>
13f101
13f101
	PR rtl-optimization/78378
13f101
	* combine.c (make_extraction): Use force_to_mode for non-{REG,MEM}
13f101
	inner only if pos is 0.
13f101
13f101
	* gcc.c-torture/execute/pr78378.c: New test.
13f101
13f101
--- gcc/combine.c
13f101
+++ gcc/combine.c
13f101
@@ -7342,6 +7342,7 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos,
13f101
   if (tmode != BLKmode
13f101
       && ((pos_rtx == 0 && (pos % BITS_PER_WORD) == 0
13f101
 	   && !MEM_P (inner)
13f101
+	   && (pos == 0 || REG_P (inner))
13f101
 	   && (inner_mode == tmode
13f101
 	       || !REG_P (inner)
13f101
 	       || TRULY_NOOP_TRUNCATION_MODES_P (tmode, inner_mode)
13f101
--- /dev/null
13f101
+++ gcc/testsuite/gcc.c-torture/execute/pr78378.c
13f101
@@ -0,0 +1,18 @@
13f101
+/* PR rtl-optimization/78378 */
13f101
+
13f101
+unsigned long long __attribute__ ((noinline, noclone))
13f101
+foo (unsigned long long x)
13f101
+{
13f101
+  x <<= 41;
13f101
+  x /= 232;
13f101
+  return 1 + (unsigned short) x;
13f101
+}
13f101
+
13f101
+int
13f101
+main ()
13f101
+{
13f101
+  unsigned long long x = foo (1);
13f101
+  if (x != 0x2c24)
13f101
+    __builtin_abort();
13f101
+  return 0;
13f101
+}
13f101