]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match.pd: When simplifying BFR of an insert, require a mode precision integral type...
authorAndrew Pinski <apinski@marvell.com>
Thu, 9 Feb 2023 15:03:54 +0000 (16:03 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 3 May 2023 12:36:26 +0000 (14:36 +0200)
The same problem as PR 88739 has crept in but
this time in match.pd when simplifying bit_field_ref of
an bit_insert. That is we are generating a BIT_FIELD_REF
of a non-mode-precision integral type.

PR tree-optimization/108688
* match.pd (bit_field_ref [bit_insert]): Avoid generating
BIT_FIELD_REFs of non-mode-precision integral operands.

* gcc.c-torture/compile/pr108688-1.c: New test.

(cherry picked from commit 44f308e59bfa0f93ae05b17e257d8563c12399fd)

gcc/match.pd
gcc/testsuite/gcc.c-torture/compile/pr108688-1.c [new file with mode: 0644]

index 1a4f0dab4639e61b93bc476d145700b621e23567..cab87c5f32d86c95a55a5f132da60317df3b2fbb 100644 (file)
@@ -5724,7 +5724,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       isize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (@1)));
   }
   (switch
-   (if (wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos))
+   (if ((!INTEGRAL_TYPE_P (TREE_TYPE (@1))
+         || type_has_mode_precision_p (TREE_TYPE (@1)))
+        && wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos))
        && wi::leu_p (wi::to_wide (@rpos) + wi::to_wide (@rsize),
                      wi::to_wide (@ipos) + isize))
     (BIT_FIELD_REF @1 @rsize { wide_int_to_tree (bitsizetype,
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c b/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c
new file mode 100644 (file)
index 0000000..43d782d
--- /dev/null
@@ -0,0 +1,15 @@
+
+
+union U { signed int d : 7; signed int e : 2; } u;
+int a, b;
+
+void
+foo (void)
+{
+  for (int i = 0; i < 64; i++)
+    {
+      u.d = a;
+      u.e ^= b;
+    }
+}
+