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.
This commit is contained in:
Tamar Christina 2021-12-01 08:40:25 +00:00
parent da9386f9a7
commit 29df53fe34
13 changed files with 49 additions and 47 deletions

View file

@ -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.

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -1,5 +1,5 @@
/* { dg-do assemble } */
/* { dg-options "-O3 -fdump-tree-dce" } */
/* { dg-additional-options "-O3 -fdump-tree-dce -w" } */
#include <stdint.h>

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -1,5 +1,5 @@
/* { dg-do assemble } */
/* { dg-options "-O1 -fdump-tree-dce" } */
/* { dg-additional-options "-O1 -fdump-tree-dce -w" } */
#include <stdint.h>

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 <stdint.h>
@ -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 } } } */

View file

@ -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 ();
}