Improve constant folding of vector lowering with vector bools
authorRichard Biener <rguenther@suse.de>
Thu, 3 Sep 2020 10:44:40 +0000 (12:44 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 3 Sep 2020 10:47:59 +0000 (12:47 +0200)
This improves the situation somewhat when vector lowering tries
to access vector bools as seen in PR96814.

2020-09-03  Richard Biener  <rguenther@suse.de>

* tree-vect-generic.c (tree_vec_extract): Remove odd
special-casing of boolean vectors.
* fold-const.c (fold_ternary_loc): Handle boolean vector
type BIT_FIELD_REFs.

gcc/fold-const.c
gcc/tree-vect-generic.c

index 1f86163022573cc1ef175c8f94204af1c72e759a..0cc80adf632fa3a5482780a41b682c258ee11afb 100644 (file)
@@ -12581,7 +12581,9 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
          && tree_fits_uhwi_p (op2))
        {
          tree eltype = TREE_TYPE (TREE_TYPE (arg0));
-         unsigned HOST_WIDE_INT width = tree_to_uhwi (TYPE_SIZE (eltype));
+         unsigned HOST_WIDE_INT width
+           = (TREE_CODE (eltype) == BOOLEAN_TYPE
+              ? TYPE_PRECISION (eltype) : tree_to_uhwi (TYPE_SIZE (eltype)));
          unsigned HOST_WIDE_INT n = tree_to_uhwi (arg1);
          unsigned HOST_WIDE_INT idx = tree_to_uhwi (op2);
 
index 6d5d65195ae6e5b8a5c8343c5f3ab67907b10f8f..d7bafa77134079faf743c1b482251311abb681c5 100644 (file)
@@ -136,19 +136,7 @@ tree_vec_extract (gimple_stmt_iterator *gsi, tree type,
        t = gimple_assign_rhs1 (def_stmt);
     }
   if (bitpos)
-    {
-      if (TREE_CODE (type) == BOOLEAN_TYPE)
-       {
-         tree itype
-           = build_nonstandard_integer_type (tree_to_uhwi (bitsize), 0);
-         tree field = gimplify_build3 (gsi, BIT_FIELD_REF, itype, t,
-                                       bitsize, bitpos);
-         return gimplify_build2 (gsi, NE_EXPR, type, field,
-                                 build_zero_cst (itype));
-       }
-      else
-       return gimplify_build3 (gsi, BIT_FIELD_REF, type, t, bitsize, bitpos);
-    }
+    return gimplify_build3 (gsi, BIT_FIELD_REF, type, t, bitsize, bitpos);
   else
     return gimplify_build1 (gsi, VIEW_CONVERT_EXPR, type, t);
 }