diff --git a/gcc/match.pd b/gcc/match.pd index 1d6428bf7e5..7b652afb43d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7237,7 +7237,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && !TYPE_UNSIGNED (TREE_TYPE (@1)) && element_precision (@1) <= element_precision (@0) - && bitwise_equal_p (@1, @2)) + && bitwise_equal_p (@1, @2) + && (!VECTOR_TYPE_P (type) + || target_supports_op_p (type, ABS_EXPR, optab_vector))) (if (TYPE_UNSIGNED (TREE_TYPE (@2))) (with { tree stype = signed_type_for (TREE_TYPE (@2)); @@ -7255,7 +7257,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && !TYPE_UNSIGNED (TREE_TYPE (@1)) && element_precision (@1) <= element_precision (@0) - && bitwise_equal_p (@1, @2)) + && bitwise_equal_p (@1, @2) + && (!VECTOR_TYPE_P (type) + || (target_supports_op_p (type, ABS_EXPR, optab_vector) + && target_supports_op_p (type, NEGATE_EXPR, optab_vector)))) (if ((ANY_INTEGRAL_TYPE_P (TREE_TYPE (@2)) && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (@2))) || TYPE_UNSIGNED (TREE_TYPE (@2))) @@ -7294,7 +7299,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (cnd (cmp (minus@0 @1 @2) zerop) @0 (minus @2 @1)) (if (!HONOR_SIGNED_ZEROS (type) - && !TYPE_UNSIGNED (type)) + && !TYPE_UNSIGNED (type) + && (!VECTOR_TYPE_P (type) + || target_supports_op_p (type, ABS_EXPR, optab_vector))) (abs @0)))) /* (A - B) <=/< 0 ? (A - B) : (B - A) same as -abs (A - B) */ (for cmp (le lt) @@ -7303,7 +7310,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (!HONOR_SIGNED_ZEROS (type) && !TYPE_UNSIGNED (type)) (if (ANY_INTEGRAL_TYPE_P (type) - && !TYPE_OVERFLOW_WRAPS (type)) + && !TYPE_OVERFLOW_WRAPS (type) + && (!VECTOR_TYPE_P (type) + || (target_supports_op_p (type, ABS_EXPR, optab_vector) + && target_supports_op_p (type, NEGATE_EXPR, optab_vector)))) (with { tree utype = unsigned_type_for (type); } diff --git a/gcc/testsuite/g++.dg/absvect.C b/gcc/testsuite/g++.dg/absvect.C index 5cf2ca307f4..d28ea846d74 100644 --- a/gcc/testsuite/g++.dg/absvect.C +++ b/gcc/testsuite/g++.dg/absvect.C @@ -1,6 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-Ofast -fdump-tree-phiopt1" } */ -/* { dg-final { scan-tree-dump-times " = ABS_EXPR ;" 1 "phiopt1" } } */ +/* { dg-additional-options "-msse4" { target { x86_64-*-* i?86-*-* } } } */ +/* { dg-final { scan-tree-dump-times " = ABS_EXPR ;" 1 "phiopt1" { target { x86_64-*-* i?86-*-* } } } } */ typedef int v2si __attribute__ ((vector_size (2 * sizeof(int)))); typedef short v2hi __attribute__ ((vector_size (2 * sizeof(short)))); diff --git a/gcc/testsuite/gcc.dg/torture/pr124555.c b/gcc/testsuite/gcc.dg/torture/pr124555.c new file mode 100644 index 00000000000..668ad7b904b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr124555.c @@ -0,0 +1,25 @@ +/* { dg-additional-options "-fwrapv" } */ + +int vsad8_c_y; +char *vsad8_c_s1, *vsad8_c_s2; +long vsad8_c_stride; +int vsad8_c() +{ + int score, x; + for (; vsad8_c_y; vsad8_c_y++) + { + x = 0; + for (; x < 8; x++) + score += (vsad8_c_s1[x] - vsad8_c_s2[x] - vsad8_c_s1[x + vsad8_c_stride] + + vsad8_c_s2[x + vsad8_c_stride]) >= 0 + ? vsad8_c_s1[x] - vsad8_c_s2[x] - + vsad8_c_s1[x + vsad8_c_stride] + + vsad8_c_s2[x + vsad8_c_stride] + : -(vsad8_c_s1[x] - vsad8_c_s2[x] - + vsad8_c_s1[x + vsad8_c_stride] + + vsad8_c_s2[x + vsad8_c_stride]); + vsad8_c_s1 += vsad8_c_stride; + vsad8_c_s2 += vsad8_c_stride; + } + return score; +}