]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match.pd: rearrange (VCE (BFR)) simplification conditions [PR125259]
authorArtemiy Volkov <artemiy.volkov@arm.com>
Mon, 11 May 2026 09:06:12 +0000 (09:06 +0000)
committerArtemiy Volkov <artemiy.volkov@arm.com>
Tue, 12 May 2026 08:19:12 +0000 (08:19 +0000)
The precondition for (view_convert (BIT_FIELD_REF)) simplification at
match.pd:5881 last fixed in r16-4735-g44c27171c36a91 is still wrong,
as it allows a vector type to be converted to/from _BitInt types (for
which precision can be smaller than size).  Address this by always
checking type_has_mode_precision_p () for all integer types.  (This fix
was posted by Richard B. at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125259#c5.)

Add a testcase as reduced in the PR as tree-ssa/pr125259.c.

Bootstrapped and regtested on aarch64, arm, and x86_64.

OK for trunk and 16?

PR middle-end/125259

gcc/ChangeLog:

* match.pd: Fix the view_convert (BIT_FIELD_REF) pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr125259.c: New test.

gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr125259.c [new file with mode: 0644]

index e27d7b75466da43a0cf3e79d86634599a7b6c01a..8dcf8c318cf8890d4c62be40e1c9668fcda020ae 100644 (file)
@@ -5326,9 +5326,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (view_convert (BIT_FIELD_REF@0 @1 @2 @3))
   (if (is_gimple_reg_type (type)
        && (!INTEGRAL_TYPE_P (type)
-          || !INTEGRAL_TYPE_P (TREE_TYPE (@0))
-          || (type_has_mode_precision_p (type)
-              && type_has_mode_precision_p (TREE_TYPE (@0)))))
+          || type_has_mode_precision_p (type))
+       && (!INTEGRAL_TYPE_P (TREE_TYPE (@0))
+          || type_has_mode_precision_p (TREE_TYPE (@0))))
    (BIT_FIELD_REF:type @1 @2 @3)))
 
 /* For integral conversions with the same precision or pointer
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr125259.c b/gcc/testsuite/gcc.dg/tree-ssa/pr125259.c
new file mode 100644 (file)
index 0000000..f9596b7
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2 -fdump-tree-forwprop1" } */
+
+typedef __attribute__((__vector_size__(4))) char V4;
+typedef __attribute__((__vector_size__(8))) char V8;
+
+_BitInt(17) foo(V8 *xx)
+{
+       V8 x = *xx;
+       V4 v = *(V4 *)&x;
+       return *(_BitInt(17) *)&v;
+}
+
+/* { dg-final { scan-tree-dump "VIEW_CONVERT_EXPR" "forwprop1" } } */