Blame SOURCES/gcc48-rh1546728.patch

22033d
2015-09-03  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
22033d
22033d
	* optabs.c (expand_binop): Don't create a broadcast vector with a
22033d
	source element wider than the inner mode.
22033d
22033d
	* gcc.target/powerpc/vec-shift.c: New test.
22033d
22033d
--- gcc/optabs.c
22033d
+++ gcc/optabs.c
22033d
@@ -1608,6 +1608,15 @@ expand_binop (machine_mode mode, optab binoptab, rtx op0, rtx op1,
22033d
 
22033d
       if (otheroptab && optab_handler (otheroptab, mode) != CODE_FOR_nothing)
22033d
 	{
22033d
+	  /* The scalar may have been extended to be too wide.  Truncate
22033d
+	     it back to the proper size to fit in the broadcast vector.  */
22033d
+	  machine_mode inner_mode = GET_MODE_INNER (mode);
22033d
+	  if (!CONST_INT_P (op1)
22033d
+	      && (GET_MODE_BITSIZE (inner_mode)
22033d
+		  < GET_MODE_BITSIZE (GET_MODE (op1))))
22033d
+	    op1 = force_reg (inner_mode,
22033d
+			     simplify_gen_unary (TRUNCATE, inner_mode, op1,
22033d
+						 GET_MODE (op1)));
22033d
 	  rtx vop1 = expand_vector_broadcast (mode, op1);
22033d
 	  if (vop1)
22033d
 	    {
22033d
--- /dev/null
22033d
+++ gcc/testsuite/gcc.target/powerpc/vec-shift.c
22033d
@@ -0,0 +1,20 @@
22033d
+/* { dg-do compile { target { powerpc*-*-* } } } */
22033d
+/* { dg-require-effective-target powerpc_altivec_ok } */
22033d
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
22033d
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power7" } } */
22033d
+/* { dg-options "-mcpu=power7 -O2" } */
22033d
+
22033d
+/* This used to ICE.  During gimplification, "i" is widened to an unsigned
22033d
+   int.  We used to fail at expand time as we tried to cram an SImode item
22033d
+   into a QImode memory slot.  This has been fixed to properly truncate the
22033d
+   shift amount when splatting it into a vector.  */
22033d
+
22033d
+typedef unsigned char v16ui __attribute__((vector_size(16)));
22033d
+
22033d
+v16ui vslb(v16ui v, unsigned char i)
22033d
+{
22033d
+	return v << i;
22033d
+}
22033d
+
22033d
+/* { dg-final { scan-assembler "vspltb" } } */
22033d
+/* { dg-final { scan-assembler "vslb" } } */