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