public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5819] match.pd: Avoid simplification into invalid BIT_FIELD_REFs [PR112673]
@ 2023-11-24 10:36 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-11-24 10:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:eebcad0ac22010fc59de9d856bb02017fccab282

commit r14-5819-geebcad0ac22010fc59de9d856bb02017fccab282
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Nov 24 11:32:28 2023 +0100

    match.pd: Avoid simplification into invalid BIT_FIELD_REFs [PR112673]
    
    The following testcase is lowered by the bitint lowering pass, then
    vectorizer vectorizes one of the loops in it, so we have
      vect__18.6_34 = VIEW_CONVERT_EXPR<vector(4) unsigned long>(x_35(D));
      _8 = BIT_FIELD_REF <vect__18.6_34, 64, 0>;
    ...
      _18 = BIT_FIELD_REF <vect__18.6_34, 64, 64>;
    etc. where x_35(D) is _BitInt(256) argument.  That is valid BIT_FIELD_REF,
    the first argument is a vector and it extracts the vector elements from it.
    Then comes forwprop4 and simplifies that using match.pd into
      _8 = (unsigned long) x_35(D);
    ...
      _18 = BIT_FIELD_REF <x_35(D), 64, 64>;
    and tree-cfg verification ICEs on the latter (though, even the first cast
    is kind of undesirable after bitint lowering, we want large/huge bitints
    lowered).  The ICE is because if BIT_FIELD_REFs first argument has
    INTEGRAL_TYPE_P, we require type_has_mode_precision_p, but that is not the
    case of _BitInt(256), it has BLKmode.
    
    The following patch fixes it by doing the BIT_FIELD_REF with VCE to
    BIT_FIELD_REF simplification only if the result is valid.
    
    2023-11-24  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/112673
            * match.pd (bit_field_ref (vce @0) -> bit_field_ref @0): Only simplify
            if either @0 doesn't have scalar integral type or if it has mode
            precision.
    
            * gcc.dg/pr112673.c: New test.

Diff:
---
 gcc/match.pd                    |  4 +++-
 gcc/testsuite/gcc.dg/pr112673.c | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index b30de36e836..61e5d3441f4 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8285,7 +8285,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 (simplify
  (BIT_FIELD_REF (view_convert @0) @1 @2)
- (BIT_FIELD_REF @0 @1 @2))
+ (if (! INTEGRAL_TYPE_P (TREE_TYPE (@0))
+      || type_has_mode_precision_p (TREE_TYPE (@0)))
+  (BIT_FIELD_REF @0 @1 @2)))
 
 (simplify
  (BIT_FIELD_REF @0 @1 integer_zerop)
diff --git a/gcc/testsuite/gcc.dg/pr112673.c b/gcc/testsuite/gcc.dg/pr112673.c
new file mode 100644
index 00000000000..531f277f3a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr112673.c
@@ -0,0 +1,10 @@
+/* PR tree-optimization/112673 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-O3" } */
+/* { dg-additional-options "-mavx2" { target i?86-*-* x86_64-*-* } } */
+
+int
+foo (_BitInt(256) x)
+{
+  return __builtin_ctzg ((unsigned _BitInt(512)) x);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-24 10:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24 10:36 [gcc r14-5819] match.pd: Avoid simplification into invalid BIT_FIELD_REFs [PR112673] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).