Commit 779fed5f by Richard Sandiford Committed by Richard Sandiford

Fix folding of vector mask EQ/NE expressions

fold_binary_loc assumed that if the type of the result wasn't a vector,
the operands wouldn't be either.  This isn't necessarily true for
EQ_EXPR and NE_EXPR of vector masks, which can return a single scalar
for the mask as a whole.

2018-01-13  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* fold-const.c (fold_binary_loc): Check the argument types
	rather than the result type when testing for a vector operation.

gcc/testsuite/
	* gcc.target/aarch64/sve/vec_bool_cmp_1.c: New test.
	* gcc.target/aarch64/sve/vec_bool_cmp_1_run.c: Likweise.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>

From-SVN: r256616
parent dbc3af4f
2018-01-13 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* fold-const.c (fold_binary_loc): Check the argument types
rather than the result type when testing for a vector operation.
2018-01-13 Richard Sandiford <richard.sandiford@linaro.org>
* doc/tm.texi.in (DWARF_LAZY_REGISTER_VALUE): Document.
* doc/tm.texi: Regenerate.
......
......@@ -9323,7 +9323,7 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR
|| code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (type) != VECTOR_TYPE
&& !VECTOR_TYPE_P (TREE_TYPE (arg0))
&& ((truth_value_p (TREE_CODE (arg0))
&& (truth_value_p (TREE_CODE (arg1))
|| (TREE_CODE (arg1) == BIT_AND_EXPR
......
2018-01-13 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* gcc.target/aarch64/sve/vec_bool_cmp_1.c: New test.
* gcc.target/aarch64/sve/vec_bool_cmp_1_run.c: Likweise.
2018-01-13 Richard Sandiford <richard.sandiford@linaro.org>
* g++.target/aarch64/sve/aarch64-sve.exp: New harness.
* g++.target/aarch64/sve/catch_1.C: New test.
......
/* { dg-do compile } */
/* { dg-options "-O2 -ftree-vectorize" } */
#include <stdint.h>
#include <stdbool.h>
#define VEC_BOOL(NAME, OP, VARTYPE, INDUCTYPE) \
void __attribute__ ((noinline, noclone)) \
vec_bool_##NAME##_##VARTYPE##_##INDUCTYPE (VARTYPE *dst, VARTYPE *src, \
INDUCTYPE start, \
INDUCTYPE n, \
INDUCTYPE mask) \
{ \
for (INDUCTYPE i = 0; i < n; i++) \
{ \
bool lhs = i >= start; \
bool rhs = (i & mask) != 0x3D; \
if (lhs OP rhs) \
dst[i] = src[i]; \
} \
}
#define TEST_OP(T, NAME, OP) \
T (NAME, OP, uint8_t, uint8_t) \
T (NAME, OP, uint16_t, uint16_t) \
T (NAME, OP, uint32_t, uint32_t) \
T (NAME, OP, uint64_t, uint64_t) \
T (NAME, OP, float, uint32_t) \
T (NAME, OP, double, uint64_t)
#define TEST_ALL(T) \
TEST_OP (T, cmpeq, ==) \
TEST_OP (T, cmpne, !=)
TEST_ALL (VEC_BOOL)
/* Both cmpne and cmpeq loops will contain an exclusive predicate or. */
/* { dg-final { scan-assembler-times {\teors?\tp[0-9]*\.b, p[0-7]/z, p[0-9]*\.b, p[0-9]*\.b\n} 12 } } */
/* cmpeq will also contain a predicate not operation. */
/* { dg-final { scan-assembler-times {\tnot\tp[0-9]*\.b, p[0-7]/z, p[0-9]*\.b\n} 6 } } */
/* { dg-do run { target { aarch64_sve_hw } } } */
/* { dg-options "-O3 -fno-inline" } */
#include "vec_bool_cmp_1.c"
#define N 103
#define TEST_VEC_BOOL(NAME, OP, VARTYPE, INDUCTYPE) \
{ \
INDUCTYPE i; \
VARTYPE src[N]; \
VARTYPE dst[N]; \
for (i = 0; i < N; i++) \
{ \
src[i] = i; \
dst[i] = i * 2; \
asm volatile ("" ::: "memory"); \
} \
vec_bool_##NAME##_##VARTYPE##_##INDUCTYPE (dst, src, 13, \
97, 0xFF); \
for (i = 0; i < 13; i++) \
if (dst[i] != (VARTYPE) (0 OP 1 ? i : i * 2)) \
__builtin_abort (); \
for (i = 13; i < 97; i++) \
if (dst[i] != (VARTYPE) (1 OP (i != 0x3D) ? i : i * 2)) \
__builtin_abort (); \
for (i = 97; i < N; i++) \
if (dst[i] != (i * 2)) \
__builtin_abort (); \
}
int __attribute__ ((optimize (1)))
main ()
{
TEST_ALL (TEST_VEC_BOOL)
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment