]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bitint: Avoid rewriting large/huge _BitInt vars into SSA after bitint lowering [PR114278]
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Mar 2024 10:00:54 +0000 (11:00 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 11 Mar 2024 10:00:54 +0000 (11:00 +0100)
The following testcase ICEs, because update-address-taken subpass of
fre5 rewrites
  _BitInt(128) b;
  vector(16) unsigned char _3;

  <bb 2> [local count: 1073741824]:
  _3 = MEM <vector(16) unsigned char> [(char * {ref-all})p_2(D)];
  MEM <vector(16) unsigned char> [(char * {ref-all})&b] = _3;
  b ={v} {CLOBBER(eos)};
to
  _BitInt(128) b;
  vector(16) unsigned char _3;

  <bb 2> [local count: 1073741824]:
  _3 = MEM <vector(16) unsigned char> [(char * {ref-all})p_2(D)];
  b_5 = VIEW_CONVERT_EXPR<_BitInt(128)>(_3);
but we can't have large/huge _BitInt vars in SSA form after the bitint
lowering except for function arguments loaded from memory, as expansion
isn't able to deal with those, it relies on bitint lowering to lower
those operations.
The following patch fixes that by setting DECL_NOT_GIMPLE_REG_P for
large/huge _BitInt vars after bitint lowering, such that we don't
rewrite them into SSA form.

2024-03-11  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/114278
* tree-ssa.cc (maybe_optimize_var): If large/huge _BitInt vars are no
longer addressable, set DECL_NOT_GIMPLE_REG_P on them.

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

gcc/testsuite/gcc.dg/bitint-99.c [new file with mode: 0644]
gcc/tree-ssa.cc

diff --git a/gcc/testsuite/gcc.dg/bitint-99.c b/gcc/testsuite/gcc.dg/bitint-99.c
new file mode 100644 (file)
index 0000000..a0aa446
--- /dev/null
@@ -0,0 +1,26 @@
+/* PR tree-optimization/114278 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2 -fno-tree-dce -fno-tree-dse -fno-tree-ccp" } */
+/* { dg-additional-options "-mavx2" { target i?86-*-* x86_64-*-* } } */
+
+void
+foo (void *p)
+{
+  _BitInt(64) b = *(_BitInt(64) *) __builtin_memmove (&b, p, sizeof (_BitInt(64)));
+}
+
+#if __BITINT_MAXWIDTH__ >= 128
+void
+bar (void *p)
+{
+  _BitInt(128) b = *(_BitInt(128) *) __builtin_memmove (&b, p, sizeof (_BitInt(128)));
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 256
+void
+baz (void *p)
+{
+  _BitInt(256) b = *(_BitInt(256) *) __builtin_memmove (&b, p, sizeof (_BitInt(256)));
+}
+#endif
index 16f42a6022aaf55f215e83849ca37420b5839e7c..27ab9cfac823253a79d98cae558a7c6f61dac1f0 100644 (file)
@@ -1785,6 +1785,20 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
              fprintf (dump_file, "\n");
            }
        }
+      else if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE
+              && (cfun->curr_properties & PROP_gimple_lbitint) != 0
+              && TYPE_PRECISION (TREE_TYPE (var)) > MAX_FIXED_MODE_SIZE)
+       {
+         /* Don't rewrite large/huge _BitInt vars after _BitInt lowering
+            into SSA form.  */
+         DECL_NOT_GIMPLE_REG_P (var) = 1;
+         if (dump_file)
+           {
+             fprintf (dump_file, "_BitInt var after its lowering: ");
+             print_generic_expr (dump_file, var);
+             fprintf (dump_file, "\n");
+           }
+       }
       else if (DECL_NOT_GIMPLE_REG_P (var))
        {
          maybe_reg = true;