]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lower-bitint: Fix up VIEW_CONVERT_EXPR handling [PR113408]
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 Jan 2024 12:55:50 +0000 (13:55 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 17 Jan 2024 12:55:50 +0000 (13:55 +0100)
Unlike NOP_EXPR/CONVERT_EXPR which are GIMPLE_UNARY_RHS, VIEW_CONVERT_EXPR
is GIMPLE_SINGLE_RHS and so gimple_assign_rhs1 contains the operand wrapped
in VIEW_CONVERT_EXPR tree.

So, to handle it like other casts we need to look through it.

2024-01-17  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/113408
* gimple-lower-bitint.cc (bitint_large_huge::handle_stmt): For
VIEW_CONVERT_EXPR, pass TREE_OPERAND (rhs1, 0) rather than rhs1
to handle_cast.

* gcc.dg/bitint-71.c: New test.

gcc/gimple-lower-bitint.cc
gcc/testsuite/gcc.dg/bitint-71.c [new file with mode: 0644]

index 672a9a33751ad611dcd847909f0b68b34e7f7c8e..d3d113578d91668f8dba873d2c73835dfb8bd49a 100644 (file)
@@ -1975,9 +1975,12 @@ bitint_large_huge::handle_stmt (gimple *stmt, tree idx)
        case INTEGER_CST:
          return handle_operand (gimple_assign_rhs1 (stmt), idx);
        CASE_CONVERT:
-       case VIEW_CONVERT_EXPR:
          return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)),
                              gimple_assign_rhs1 (stmt), idx);
+       case VIEW_CONVERT_EXPR:
+         return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)),
+                             TREE_OPERAND (gimple_assign_rhs1 (stmt), 0),
+                             idx);
        default:
          break;
        }
diff --git a/gcc/testsuite/gcc.dg/bitint-71.c b/gcc/testsuite/gcc.dg/bitint-71.c
new file mode 100644 (file)
index 0000000..f7ff871
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR tree-optimization/113408 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+#if __BITINT_MAXWIDTH__ >= 713
+struct A { _BitInt(713) b; } g;
+#else
+struct A { _BitInt(49) b; } g;
+#endif
+int f;
+
+void
+foo (void)
+{
+  struct A j = g;
+  if (j.b)
+    f = 0;
+}