diff mbox series

Add tree_fits_uhwi_p tests to BIT_FIELD_REF folder

Message ID 87k1wyhr9a.fsf@linaro.org
State New
Headers show
Series Add tree_fits_uhwi_p tests to BIT_FIELD_REF folder | expand

Commit Message

Richard Sandiford Jan. 4, 2018, 10:06 a.m. UTC
The first BIT_FIELD_REF folding pattern assumed without checking that
operands satisfy tree_fits_uhwi_p.  The second pattern does check this:

      /* On constants we can use native encode/interpret to constant
         fold (nearly) all BIT_FIELD_REFs.  */
      if (CONSTANT_CLASS_P (arg0)
          && can_native_interpret_type_p (type)
          && BITS_PER_UNIT == 8
          && tree_fits_uhwi_p (op1)
          && tree_fits_uhwi_p (op2))

so this patch adds the checks to the first pattern too.  This is needed
for POLY_INT_CST bit positions.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
Also tested by comparing the before and after assembly output for at
least one target per CPU directory.  OK to install?

Richard


2018-01-04  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* fold-const.c (fold_ternary_loc): Check tree_fits_uhwi_p before
	using tree_to_uhwi.

Comments

Jeff Law Jan. 4, 2018, 5:51 p.m. UTC | #1
On 01/04/2018 03:06 AM, Richard Sandiford wrote:
> The first BIT_FIELD_REF folding pattern assumed without checking that

> operands satisfy tree_fits_uhwi_p.  The second pattern does check this:

> 

>       /* On constants we can use native encode/interpret to constant

>          fold (nearly) all BIT_FIELD_REFs.  */

>       if (CONSTANT_CLASS_P (arg0)

>           && can_native_interpret_type_p (type)

>           && BITS_PER_UNIT == 8

>           && tree_fits_uhwi_p (op1)

>           && tree_fits_uhwi_p (op2))

> 

> so this patch adds the checks to the first pattern too.  This is needed

> for POLY_INT_CST bit positions.

> 

> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.

> Also tested by comparing the before and after assembly output for at

> least one target per CPU directory.  OK to install?

> 

> Richard

> 

> 

> 2018-01-04  Richard Sandiford  <richard.sandiford@linaro.org>

> 

> gcc/

> 	* fold-const.c (fold_ternary_loc): Check tree_fits_uhwi_p before

> 	using tree_to_uhwi.

OK.
jeff
Richard Biener Jan. 5, 2018, 8:58 a.m. UTC | #2
On Thu, Jan 4, 2018 at 11:06 AM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> The first BIT_FIELD_REF folding pattern assumed without checking that

> operands satisfy tree_fits_uhwi_p.  The second pattern does check this:

>

>       /* On constants we can use native encode/interpret to constant

>          fold (nearly) all BIT_FIELD_REFs.  */

>       if (CONSTANT_CLASS_P (arg0)

>           && can_native_interpret_type_p (type)

>           && BITS_PER_UNIT == 8

>           && tree_fits_uhwi_p (op1)

>           && tree_fits_uhwi_p (op2))

>

> so this patch adds the checks to the first pattern too.  This is needed

> for POLY_INT_CST bit positions.

>

> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.

> Also tested by comparing the before and after assembly output for at

> least one target per CPU directory.  OK to install?


Ok.  It's of course because verify_expr verified that.

Richard.

> Richard

>

>

> 2018-01-04  Richard Sandiford  <richard.sandiford@linaro.org>

>

> gcc/

>         * fold-const.c (fold_ternary_loc): Check tree_fits_uhwi_p before

>         using tree_to_uhwi.

>

> Index: gcc/fold-const.c

> ===================================================================

> --- gcc/fold-const.c    2018-01-03 21:42:34.349039784 +0000

> +++ gcc/fold-const.c    2018-01-04 10:06:02.165809202 +0000

> @@ -11643,7 +11643,9 @@ fold_ternary_loc (location_t loc, enum t

>        if (TREE_CODE (arg0) == VECTOR_CST

>           && (type == TREE_TYPE (TREE_TYPE (arg0))

>               || (TREE_CODE (type) == VECTOR_TYPE

> -                 && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0)))))

> +                 && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0))))

> +         && tree_fits_uhwi_p (op1)

> +         && tree_fits_uhwi_p (op2))

>         {

>           tree eltype = TREE_TYPE (TREE_TYPE (arg0));

>           unsigned HOST_WIDE_INT width = tree_to_uhwi (TYPE_SIZE (eltype));
diff mbox series

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	2018-01-03 21:42:34.349039784 +0000
+++ gcc/fold-const.c	2018-01-04 10:06:02.165809202 +0000
@@ -11643,7 +11643,9 @@  fold_ternary_loc (location_t loc, enum t
       if (TREE_CODE (arg0) == VECTOR_CST
 	  && (type == TREE_TYPE (TREE_TYPE (arg0))
 	      || (TREE_CODE (type) == VECTOR_TYPE
-		  && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0)))))
+		  && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0))))
+	  && tree_fits_uhwi_p (op1)
+	  && tree_fits_uhwi_p (op2))
 	{
 	  tree eltype = TREE_TYPE (TREE_TYPE (arg0));
 	  unsigned HOST_WIDE_INT width = tree_to_uhwi (TYPE_SIZE (eltype));