Blame SOURCES/gcc48-rh1469697-14.patch

001c85
commit 21397732bbcef3347c0d5ff8a0ee5163e803e2fb
001c85
Author: Jeff Law <law@redhat.com>
001c85
Date:   Mon Oct 2 12:30:26 2017 -0600
001c85
001c85
    Dependencies for aarch64 work
001c85
001c85
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
001c85
index 07ff7031b35..91dd5b7fc02 100644
001c85
--- a/gcc/config/aarch64/aarch64-protos.h
001c85
+++ b/gcc/config/aarch64/aarch64-protos.h
001c85
@@ -181,6 +181,7 @@ unsigned aarch64_dbx_register_number (unsigned);
001c85
 unsigned aarch64_trampoline_size (void);
001c85
 void aarch64_asm_output_labelref (FILE *, const char *);
001c85
 void aarch64_elf_asm_named_section (const char *, unsigned, tree);
001c85
+const char * aarch64_output_probe_stack_range (rtx, rtx);
001c85
 void aarch64_expand_epilogue (bool);
001c85
 void aarch64_expand_mov_immediate (rtx, rtx);
001c85
 void aarch64_expand_prologue (void);
001c85
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
001c85
index 5afc167d569..cadf193cfcf 100644
001c85
--- a/gcc/config/aarch64/aarch64.c
001c85
+++ b/gcc/config/aarch64/aarch64.c
001c85
@@ -969,6 +969,199 @@ aarch64_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
001c85
   return true;
001c85
 }
001c85
 
001c85
+static int
001c85
+aarch64_internal_mov_immediate (rtx dest, rtx imm, bool generate,
001c85
+				enum machine_mode mode)
001c85
+{
001c85
+  int i;
001c85
+  unsigned HOST_WIDE_INT val, val2, mask;
001c85
+  int one_match, zero_match;
001c85
+  int num_insns;
001c85
+
001c85
+  val = INTVAL (imm);
001c85
+
001c85
+  if (aarch64_move_imm (val, mode))
001c85
+    {
001c85
+      if (generate)
001c85
+	emit_insn (gen_rtx_SET (VOIDmode, dest, imm));
001c85
+      return 1;
001c85
+    }
001c85
+
001c85
+  /* Check to see if the low 32 bits are either 0xffffXXXX or 0xXXXXffff
001c85
+     (with XXXX non-zero). In that case check to see if the move can be done in
001c85
+     a smaller mode.  */
001c85
+  val2 = val & 0xffffffff;
001c85
+  if (mode == DImode
001c85
+      && aarch64_move_imm (val2, SImode)
001c85
+      && (((val >> 32) & 0xffff) == 0 || (val >> 48) == 0))
001c85
+    {
001c85
+      if (generate)
001c85
+	emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_INT (val2)));
001c85
+
001c85
+      /* Check if we have to emit a second instruction by checking to see
001c85
+         if any of the upper 32 bits of the original DI mode value is set.  */
001c85
+      if (val == val2)
001c85
+	return 1;
001c85
+
001c85
+      i = (val >> 48) ? 48 : 32;
001c85
+
001c85
+      if (generate)
001c85
+	 emit_insn (gen_insv_immdi (dest, GEN_INT (i),
001c85
+				    GEN_INT ((val >> i) & 0xffff)));
001c85
+
001c85
+      return 2;
001c85
+    }
001c85
+
001c85
+  if ((val >> 32) == 0 || mode == SImode)
001c85
+    {
001c85
+      if (generate)
001c85
+	{
001c85
+	  emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_INT (val & 0xffff)));
001c85
+	  if (mode == SImode)
001c85
+	    emit_insn (gen_insv_immsi (dest, GEN_INT (16),
001c85
+				       GEN_INT ((val >> 16) & 0xffff)));
001c85
+	  else
001c85
+	    emit_insn (gen_insv_immdi (dest, GEN_INT (16),
001c85
+				       GEN_INT ((val >> 16) & 0xffff)));
001c85
+	}
001c85
+      return 2;
001c85
+    }
001c85
+
001c85
+  /* Remaining cases are all for DImode.  */
001c85
+
001c85
+  mask = 0xffff;
001c85
+  zero_match = ((val & mask) == 0) + ((val & (mask << 16)) == 0) +
001c85
+    ((val & (mask << 32)) == 0) + ((val & (mask << 48)) == 0);
001c85
+  one_match = ((~val & mask) == 0) + ((~val & (mask << 16)) == 0) +
001c85
+    ((~val & (mask << 32)) == 0) + ((~val & (mask << 48)) == 0);
001c85
+
001c85
+  if (zero_match != 2 && one_match != 2)
001c85
+    {
001c85
+      /* Try emitting a bitmask immediate with a movk replacing 16 bits.
001c85
+	 For a 64-bit bitmask try whether changing 16 bits to all ones or
001c85
+	 zeroes creates a valid bitmask.  To check any repeated bitmask,
001c85
+	 try using 16 bits from the other 32-bit half of val.  */
001c85
+
001c85
+      for (i = 0; i < 64; i += 16, mask <<= 16)
001c85
+	{
001c85
+	  val2 = val & ~mask;
001c85
+	  if (val2 != val && aarch64_bitmask_imm (val2, mode))
001c85
+	    break;
001c85
+	  val2 = val | mask;
001c85
+	  if (val2 != val && aarch64_bitmask_imm (val2, mode))
001c85
+	    break;
001c85
+	  val2 = val2 & ~mask;
001c85
+	  val2 = val2 | (((val2 >> 32) | (val2 << 32)) & mask);
001c85
+	  if (val2 != val && aarch64_bitmask_imm (val2, mode))
001c85
+	    break;
001c85
+	}
001c85
+      if (i != 64)
001c85
+	{
001c85
+	  if (generate)
001c85
+	    {
001c85
+	      emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_INT (val2)));
001c85
+	      emit_insn (gen_insv_immdi (dest, GEN_INT (i),
001c85
+					 GEN_INT ((val >> i) & 0xffff)));
001c85
+	    }
001c85
+	  return 2;
001c85
+	}
001c85
+    }
001c85
+
001c85
+  /* Generate 2-4 instructions, skipping 16 bits of all zeroes or ones which
001c85
+     are emitted by the initial mov.  If one_match > zero_match, skip set bits,
001c85
+     otherwise skip zero bits.  */
001c85
+
001c85
+  num_insns = 1;
001c85
+  mask = 0xffff;
001c85
+  val2 = one_match > zero_match ? ~val : val;
001c85
+  i = (val2 & mask) != 0 ? 0 : (val2 & (mask << 16)) != 0 ? 16 : 32;
001c85
+
001c85
+  if (generate)
001c85
+    emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_INT (one_match > zero_match
001c85
+					   ? (val | ~(mask << i))
001c85
+					   : (val & (mask << i)))));
001c85
+  for (i += 16; i < 64; i += 16)
001c85
+    {
001c85
+      if ((val2 & (mask << i)) == 0)
001c85
+	continue;
001c85
+      if (generate)
001c85
+	emit_insn (gen_insv_immdi (dest, GEN_INT (i),
001c85
+				   GEN_INT ((val >> i) & 0xffff)));
001c85
+      num_insns ++;
001c85
+    }
001c85
+
001c85
+  return num_insns;
001c85
+}
001c85
+
001c85
+/* Add DELTA to REGNUM in mode MODE.  SCRATCHREG can be used to hold a
001c85
+   temporary value if necessary.  FRAME_RELATED_P should be true if
001c85
+   the RTX_FRAME_RELATED flag should be set and CFA adjustments added
001c85
+   to the generated instructions.  If SCRATCHREG is known to hold
001c85
+   abs (delta), EMIT_MOVE_IMM can be set to false to avoid emitting the
001c85
+   immediate again.
001c85
+
001c85
+   Since this function may be used to adjust the stack pointer, we must
001c85
+   ensure that it cannot cause transient stack deallocation (for example
001c85
+   by first incrementing SP and then decrementing when adjusting by a
001c85
+   large immediate).  */
001c85
+
001c85
+static void
001c85
+aarch64_add_constant_internal (enum machine_mode mode, int regnum,
001c85
+			       int scratchreg, HOST_WIDE_INT delta,
001c85
+			       bool frame_related_p, bool emit_move_imm)
001c85
+{
001c85
+  HOST_WIDE_INT mdelta = abs_hwi (delta);
001c85
+  rtx this_rtx = gen_rtx_REG (mode, regnum);
001c85
+  rtx insn;
001c85
+
001c85
+  if (!mdelta)
001c85
+    return;
001c85
+
001c85
+  /* Single instruction adjustment.  */
001c85
+  if (aarch64_uimm12_shift (mdelta))
001c85
+    {
001c85
+      insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (delta)));
001c85
+      RTX_FRAME_RELATED_P (insn) = frame_related_p;
001c85
+      return;
001c85
+    }
001c85
+
001c85
+  /* Emit 2 additions/subtractions if the adjustment is less than 24 bits.
001c85
+     Only do this if mdelta is not a 16-bit move as adjusting using a move
001c85
+     is better.  */
001c85
+  if (mdelta < 0x1000000 && !aarch64_move_imm (mdelta, mode))
001c85
+    {
001c85
+      HOST_WIDE_INT low_off = mdelta & 0xfff;
001c85
+
001c85
+      low_off = delta < 0 ? -low_off : low_off;
001c85
+      insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (low_off)));
001c85
+      RTX_FRAME_RELATED_P (insn) = frame_related_p;
001c85
+      insn = emit_insn (gen_add2_insn (this_rtx, GEN_INT (delta - low_off)));
001c85
+      RTX_FRAME_RELATED_P (insn) = frame_related_p;
001c85
+      return;
001c85
+    }
001c85
+
001c85
+  /* Emit a move immediate if required and an addition/subtraction.  */
001c85
+  rtx scratch_rtx = gen_rtx_REG (mode, scratchreg);
001c85
+  if (emit_move_imm)
001c85
+    aarch64_internal_mov_immediate (scratch_rtx, GEN_INT (mdelta), true, mode);
001c85
+  insn = emit_insn (delta < 0 ? gen_sub2_insn (this_rtx, scratch_rtx)
001c85
+			      : gen_add2_insn (this_rtx, scratch_rtx));
001c85
+  if (frame_related_p)
001c85
+    {
001c85
+      RTX_FRAME_RELATED_P (insn) = frame_related_p;
001c85
+      rtx adj = plus_constant (mode, this_rtx, delta);
001c85
+      add_reg_note (insn , REG_CFA_ADJUST_CFA,
001c85
+		    gen_rtx_SET (VOIDmode, this_rtx, adj));
001c85
+    }
001c85
+}
001c85
+
001c85
+static inline void
001c85
+aarch64_sub_sp (int scratchreg, HOST_WIDE_INT delta, bool frame_related_p)
001c85
+{
001c85
+  aarch64_add_constant_internal (Pmode, SP_REGNUM, scratchreg, -delta,
001c85
+				 frame_related_p, true);
001c85
+}
001c85
+
001c85
 /* Implement TARGET_PASS_BY_REFERENCE.  */
001c85
 
001c85
 static bool
001c85
@@ -1476,6 +1669,47 @@ aarch64_libgcc_cmp_return_mode (void)
001c85
   return SImode;
001c85
 }
001c85
 
001c85
+#define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
001c85
+
001c85
+/* We use the 12-bit shifted immediate arithmetic instructions so values
001c85
+   must be multiple of (1 << 12), i.e. 4096.  */
001c85
+#define ARITH_FACTOR 4096
001c85
+
001c85
+/* Probe a range of stack addresses from REG1 to REG2 inclusive.  These are
001c85
+   absolute addresses.  */
001c85
+
001c85
+const char *
001c85
+aarch64_output_probe_stack_range (rtx reg1, rtx reg2)
001c85
+{
001c85
+  static int labelno = 0;
001c85
+  char loop_lab[32];
001c85
+  rtx xops[2];
001c85
+
001c85
+  ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
001c85
+
001c85
+  /* Loop.  */
001c85
+  ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
001c85
+
001c85
+  /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL.  */
001c85
+  xops[0] = reg1;
001c85
+  xops[1] = GEN_INT (PROBE_INTERVAL);
001c85
+  output_asm_insn ("sub\t%0, %0, %1", xops);
001c85
+
001c85
+  /* Probe at TEST_ADDR.  */
001c85
+  output_asm_insn ("str\txzr, [%0]", xops);
001c85
+
001c85
+  /* Test if TEST_ADDR == LAST_ADDR.  */
001c85
+  xops[1] = reg2;
001c85
+  output_asm_insn ("cmp\t%0, %1", xops);
001c85
+
001c85
+  /* Branch.  */
001c85
+  fputs ("\tb.ne\t", asm_out_file);
001c85
+  assemble_name_raw (asm_out_file, loop_lab);
001c85
+  fputc ('\n', asm_out_file);
001c85
+
001c85
+  return "";
001c85
+}
001c85
+
001c85
 static bool
001c85
 aarch64_frame_pointer_required (void)
001c85
 {
001c85
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
001c85
index 91299901bbf..17082486ac8 100644
001c85
--- a/gcc/config/aarch64/aarch64.md
001c85
+++ b/gcc/config/aarch64/aarch64.md
001c85
@@ -88,6 +88,7 @@
001c85
     UNSPEC_ST4
001c85
     UNSPEC_TLS
001c85
     UNSPEC_TLSDESC
001c85
+    UNSPECV_PROBE_STACK_RANGE   ; Represent stack range probing.
001c85
     UNSPEC_VSTRUCTDUMMY
001c85
 ])
001c85
 
001c85
@@ -3399,6 +3400,18 @@
001c85
   [(set_attr "length" "0")]
001c85
 )
001c85
 
001c85
+(define_insn "probe_stack_range"
001c85
+  [(set (match_operand:DI 0 "register_operand" "=r")
001c85
+	(unspec_volatile:DI [(match_operand:DI 1 "register_operand" "0")
001c85
+			     (match_operand:DI 2 "register_operand" "r")]
001c85
+			      UNSPECV_PROBE_STACK_RANGE))]
001c85
+  ""
001c85
+{
001c85
+  return aarch64_output_probe_stack_range (operands[0], operands[2]);
001c85
+}
001c85
+  [(set_attr "length" "32")]
001c85
+)
001c85
+
001c85
 ;; Named pattern for expanding thread pointer reference.
001c85
 (define_expand "get_thread_pointerdi"
001c85
   [(match_operand:DI 0 "register_operand" "=r")]