From: Tamar Christina Date: Wed, 1 Dec 2021 08:40:25 +0000 (+0000) Subject: middle-end: move bitmask match.pd pattern and update tests X-Git-Tag: basepoints/gcc-13~2663 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29df53fe349073a9210df70ae45662cb3f4a0556;p=thirdparty%2Fgcc.git middle-end: move bitmask match.pd pattern and update tests Following the previous bugfix this addresses the cosmetic and test issues. The vector tests are moved to vect and the scalar are left where they are. gcc/ChangeLog: * match.pd: Move below pattern that rewrites to EQ, NE. * tree.c (bitmask_inv_cst_vector_p): Correct do .. while indentation. gcc/testsuite/ChangeLog: * gcc.dg/bic-bitmask-10.c: Moved to gcc.dg/vect/vect-bic-bitmask-10.c. * gcc.dg/bic-bitmask-11.c: Moved to gcc.dg/vect/vect-bic-bitmask-11.c. * gcc.dg/bic-bitmask-12.c: Moved to gcc.dg/vect/vect-bic-bitmask-12.c. * gcc.dg/bic-bitmask-3.c: Moved to gcc.dg/vect/vect-bic-bitmask-3.c. * gcc.dg/bic-bitmask-23.c: Moved to gcc.dg/vect/vect-bic-bitmask-23.c. * gcc.dg/bic-bitmask-2.c: Moved to gcc.dg/vect/vect-bic-bitmask-2.c. * gcc.dg/bic-bitmask-4.c: Moved to gcc.dg/vect/vect-bic-bitmask-4.c. * gcc.dg/bic-bitmask-5.c: Moved to gcc.dg/vect/vect-bic-bitmask-5.c. * gcc.dg/bic-bitmask-6.c: Moved to gcc.dg/vect/vect-bic-bitmask-6.c. * gcc.dg/bic-bitmask-8.c: Moved to gcc.dg/vect/vect-bic-bitmask-8.c. * gcc.dg/bic-bitmask-9.c: Moved to gcc.dg/vect/vect-bic-bitmask-9.c. --- diff --git a/gcc/match.pd b/gcc/match.pd index d467a1c4e453..0a00b08e2ab9 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5215,20 +5215,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (eqcmp (bit_and @1 { wide_int_to_tree (ty, mask - rhs); }) { build_zero_cst (ty); })))))) -/* Transform comparisons of the form (X & Y) CMP 0 to X CMP2 Z - where ~Y + 1 == pow2 and Z = ~Y. */ -(for cst (VECTOR_CST INTEGER_CST) - (for cmp (eq ne) - icmp (le gt) - (simplify - (cmp (bit_and:c@2 @0 cst@1) integer_zerop) - (with { tree csts = bitmask_inv_cst_vector_p (@1); } - (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))) - (if (TYPE_UNSIGNED (TREE_TYPE (@1))) - (icmp @0 { csts; }) - (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); } - (icmp (convert:utype @0) { csts; })))))))) - /* -A CMP -B -> B CMP A. */ (for cmp (tcc_comparison) scmp (swapped_tcc_comparison) @@ -5715,6 +5701,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) replace if (x == 0) with tem = ~x; if (tem != 0) which is clearly less optimal and which we'll transform again in forwprop. */ +/* Transform comparisons of the form (X & Y) CMP 0 to X CMP2 Z + where ~Y + 1 == pow2 and Z = ~Y. */ +(for cst (VECTOR_CST INTEGER_CST) + (for cmp (eq ne) + icmp (le gt) + (simplify + (cmp (bit_and:c@2 @0 cst@1) integer_zerop) + (with { tree csts = bitmask_inv_cst_vector_p (@1); } + (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))) + (if (TYPE_UNSIGNED (TREE_TYPE (@1))) + (icmp @0 { csts; }) + (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); } + (icmp (convert:utype @0) { csts; })))))))) + /* When one argument is a constant, overflow detection can be simplified. Currently restricted to single use so as not to interfere too much with ADD_OVERFLOW detection in tree-ssa-math-opts.c. diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-10.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-10.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-10.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-10.c index 0d0416028ebe..fe4f677b64dc 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-10.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-10.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -18,7 +18,7 @@ void fun2(int32_t *x, int n) } #define TYPE int32_t -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump {<=\s*.+\{ 255,.+\}} dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967290,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-11.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-11.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-11.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-11.c index 0e589c962902..b77f4d42450f 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-11.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-11.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~255)) != 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump {>\s*.+\{ 255,.+\}} dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967290,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-12.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-12.c similarity index 89% rename from gcc/testsuite/gcc.dg/bic-bitmask-12.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-12.c index 50eb563f3b1a..30d36f452014 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-12.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-12.c @@ -1,5 +1,5 @@ /* { dg-do assemble } */ -/* { dg-options "-O3 -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -fdump-tree-dce -w" } */ #include diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-3.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-2.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-3.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-2.c index 59ba9a414ae6..58c0b9254bad 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-3.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-2.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~255)) == 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-times {<=\s*.+\{ 255,.+\}} 1 dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967040,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-23.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-23.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-23.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-23.c index b41651b962f1..67119d32f751 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-23.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-23.c @@ -1,5 +1,5 @@ /* { dg-do assemble } */ -/* { dg-options "-O1 -fdump-tree-dce" } */ +/* { dg-additional-options "-O1 -fdump-tree-dce -w" } */ #include diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-2.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-3.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-2.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-3.c index 59ba9a414ae6..58c0b9254bad 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-2.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-3.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~255)) == 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-times {<=\s*.+\{ 255,.+\}} 1 dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967040,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-4.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-4.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-4.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-4.c index 7e0614d458ca..6e2da41bac12 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-4.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-4.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~255)) >= 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-times {=\s*.+\{ 1,.+\}} 1 dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967040,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-5.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-5.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-5.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-5.c index e71b17d12727..5ef0f46c0b17 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-5.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-5.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~255)) > 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-times {>\s*.+\{ 255,.+\}} 1 dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967040,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-6.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-6.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-6.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-6.c index a48a226efc15..22e5f885bebe 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-6.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-6.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~255)) <= 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-times {<=\s*.+\{ 255,.+\}} 1 dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967040,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-8.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-8.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-8.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-8.c index cd06e0ce7be1..edff5428c545 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-8.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-8.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~1)) != 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-times {>\s*.+\{ 1,.+\}} 1 dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump-not {&\s*.+\{ 4294967294,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/testsuite/gcc.dg/bic-bitmask-9.c b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-9.c similarity index 86% rename from gcc/testsuite/gcc.dg/bic-bitmask-9.c rename to gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-9.c index 3d88b74787ad..319d80e672f2 100644 --- a/gcc/testsuite/gcc.dg/bic-bitmask-9.c +++ b/gcc/testsuite/gcc.dg/vect/vect-bic-bitmask-9.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-O3 -save-temps -fdump-tree-dce" } */ +/* { dg-additional-options "-O3 -save-temps -fdump-tree-dce -w" } */ #include @@ -17,7 +17,7 @@ void fun2(uint32_t *x, int n) x[i] = (x[i]&(~5)) == 0; } -#include "bic-bitmask.h" +#include "../bic-bitmask.h" /* { dg-final { scan-tree-dump-not {<=\s*.+\{ 4294967289,.+\}} dce7 { target vect_int } } } */ /* { dg-final { scan-tree-dump {&\s*.+\{ 4294967290,.+\}} dce7 { target vect_int } } } */ diff --git a/gcc/tree.c b/gcc/tree.c index 4d91fdea758e..72cceda568f5 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -10306,22 +10306,24 @@ bitmask_inv_cst_vector_p (tree t) tree ty = unsigned_type_for (TREE_TYPE (cst)); - do { - if (idx > 0) - cst = vector_cst_elt (t, idx); - wide_int icst = wi::to_wide (cst); - wide_int inv = wi::bit_not (icst); - icst = wi::add (1, inv); - if (wi::popcount (icst) != 1) - return NULL_TREE; + do + { + if (idx > 0) + cst = vector_cst_elt (t, idx); + wide_int icst = wi::to_wide (cst); + wide_int inv = wi::bit_not (icst); + icst = wi::add (1, inv); + if (wi::popcount (icst) != 1) + return NULL_TREE; - tree newcst = wide_int_to_tree (ty, inv); + tree newcst = wide_int_to_tree (ty, inv); - if (uniform) - return build_uniform_cst (newtype, newcst); + if (uniform) + return build_uniform_cst (newtype, newcst); - builder.quick_push (newcst); - } while (++idx < nelts); + builder.quick_push (newcst); + } + while (++idx < nelts); return builder.build (); }