* fold-const.c (fold_ternary): Optimize BIT_FIELD_REF of VECTOR_CST.
authorJakub Jelinek <jakub@redhat.com>
Wed, 1 Jun 2005 10:13:36 +0000 (12:13 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 1 Jun 2005 10:13:36 +0000 (12:13 +0200)
From-SVN: r100442

gcc/ChangeLog
gcc/fold-const.c

index 6214421b91459aca9fc9fe168a1d8a9f94f35efe..01a685a22a1266e1033b21f6fded939b9f83ccbe 100644 (file)
@@ -1,5 +1,7 @@
 2005-06-01  Jakub Jelinek  <jakub@redhat.com>
 
+       * fold-const.c (fold_ternary): Optimize BIT_FIELD_REF of VECTOR_CST.
+
        * config/i386/xmmintrin.h (_mm_setzero_ps, _mm_set_ss, _mm_set1_ps,
        _mm_set_ps, _mm_setr_ps): Add __extension__.
        * config/i386/emmintrin.h (_mm_set_sd, _mm_set1_pd, _mm_set_pd,
index 18e92e27c6ab8916726236e9b8c83b2f436e4544..13984d1c8be0b4274eca63b8a6057bab0d8237dc 100644 (file)
@@ -10284,6 +10284,29 @@ fold_ternary (enum tree_code code, tree type, tree op0, tree op1, tree op2)
        }
       return NULL_TREE;
 
+    case BIT_FIELD_REF:
+      if (TREE_CODE (arg0) == VECTOR_CST
+         && type == TREE_TYPE (TREE_TYPE (arg0))
+         && host_integerp (arg1, 1)
+         && host_integerp (op2, 1))
+       {
+         unsigned HOST_WIDE_INT width = tree_low_cst (arg1, 1);
+         unsigned HOST_WIDE_INT idx = tree_low_cst (op2, 1);
+
+         if (width != 0
+             && simple_cst_equal (arg1, TYPE_SIZE (type)) == 1
+             && (idx % width) == 0
+             && (idx = idx / width)
+                < TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
+           {
+             tree elements = TREE_VECTOR_CST_ELTS (arg0);
+             while (idx-- > 0)
+               elements = TREE_CHAIN (elements);
+             return TREE_VALUE (elements);
+           }
+       }
+      return NULL_TREE;
+
     default:
       return NULL_TREE;
     } /* switch (code) */