mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
middle-end/123107 - avoid invalid vector folding
We fold (v >> CST) == { 0, 0.. } into v < { 0, 0.. } but fail to
validate that's valid for the target. The following adds such check,
making sure to apply after IPA (due to offloading) and only when
the original form wasn't valid for the target (like before vector
lowering) or when the new form is. In particular in this case
we have an equality compare resulting in a non-vector which we
can handle, but a similar LT/GT is never handled.
PR middle-end/123107
* fold-const.cc (fold_binary_loc): Guard (v >> CST) == { 0, 0.. }
to v < { 0, 0.. } folding.
* gcc.dg/torture/pr123107.c: New testcase.
This commit is contained in:
committed by
Richard Biener
parent
bba999a7f3
commit
ae0cdb01b0
@@ -86,6 +86,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include "vec-perm-indices.h"
|
||||
#include "asan.h"
|
||||
#include "gimple-range.h"
|
||||
#include "optabs-tree.h"
|
||||
|
||||
/* Nonzero if we are folding constants inside an initializer or a C++
|
||||
manifestly-constant-evaluated context; zero otherwise.
|
||||
@@ -12409,8 +12410,20 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
|
||||
itype = signed_type_for (itype);
|
||||
arg00 = fold_convert_loc (loc, itype, arg00);
|
||||
}
|
||||
return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
|
||||
type, arg00, build_zero_cst (itype));
|
||||
enum tree_code code2 = code == EQ_EXPR ? GE_EXPR : LT_EXPR;
|
||||
/* Make sure to transform vector compares only to supported
|
||||
ones or from unsupported ones and check that only after
|
||||
IPA so offloaded code is handled correctly in this regard. */
|
||||
if (!VECTOR_TYPE_P (itype)
|
||||
|| (cfun
|
||||
&& cfun->after_inlining
|
||||
/* We can jump on EQ/NE but not GE/LT. */
|
||||
&& VECTOR_BOOLEAN_TYPE_P (type)
|
||||
&& (expand_vec_cmp_expr_p (itype, type, code2)
|
||||
|| !expand_vec_cmp_expr_p (TREE_TYPE (op0),
|
||||
type, code))))
|
||||
return fold_build2_loc (loc, code2,
|
||||
type, arg00, build_zero_cst (itype));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
gcc/testsuite/gcc.dg/torture/pr123107.c
Normal file
18
gcc/testsuite/gcc.dg/torture/pr123107.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-additional-options "-Wno-psabi" } */
|
||||
/* { dg-additional-options "-mavx2" { target { x86_64-*-* i?86-*-* } } } */
|
||||
|
||||
#define BS_VEC(type, num) type __attribute__((vector_size(num * sizeof(type))))
|
||||
|
||||
int f( BS_VEC(short, 16)
|
||||
BS_TEMP_206)
|
||||
{
|
||||
BS_TEMP_206 = BS_TEMP_206 < 0;
|
||||
if (BS_TEMP_206[0] | BS_TEMP_206[1] | BS_TEMP_206[2] | BS_TEMP_206[3]
|
||||
| BS_TEMP_206[4] | BS_TEMP_206[5] | BS_TEMP_206[6] | BS_TEMP_206[7]
|
||||
| BS_TEMP_206[8] | BS_TEMP_206[9] | BS_TEMP_206[10]
|
||||
| BS_TEMP_206[11] | BS_TEMP_206[12] | BS_TEMP_206[13]
|
||||
| BS_TEMP_206[14] | BS_TEMP_206[15])
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user