forwprop: Handle RAW_DATA_CST in check_ctz_array
In order to stress test RAW_DATA_CST handling, I've tested trunk gcc with r15-6339 reapplied and a hack where I've changed const unsigned int raw_data_min_len = 128; to const unsigned int raw_data_min_len = 2; in cp_lexer_new_main and 64 to 4 several times in c_parser_initval and c_maybe_optimize_large_byte_initializer, so that RAW_DATA_CST doesn't trigger just on very large initializers, but even quite small ones. One of the regressions (will work on the others next) was that pr90838.c testcase regressed, check_ctz_array needs to handle RAW_DATA_CST, otherwise on larger initializers or if those come from #embed just won't trigger. The new testcase shows when it doesn't trigger anymore (regression from 14). The patch just handles RAW_DATA_CST in the CONSTRUCTOR_ELTS the same as is it was a series of INTEGER_CSTs. 2025-01-02 Jakub Jelinek <jakub@redhat.com> * tree-ssa-forwprop.cc (check_ctz_array): Handle also RAW_DATA_CST in the CONSTRUCTOR_ELTS. * gcc.dg/pr90838-2.c: New test.
This commit is contained in:
parent
29bc14c750
commit
cb403df46f
2 changed files with 64 additions and 4 deletions
39
gcc/testsuite/gcc.dg/pr90838-2.c
Normal file
39
gcc/testsuite/gcc.dg/pr90838-2.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -fdump-tree-forwprop2-details" } */
|
||||
/* { dg-additional-options "-mbmi" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } */
|
||||
/* { dg-additional-options "-march=rv64gc_zbb" { target { rv64 } } } */
|
||||
/* { dg-additional-options "-march=rv32gc_zbb" { target { rv32 } } } */
|
||||
/* { dg-require-effective-target int32plus } */
|
||||
|
||||
static const unsigned long long magic = 0x03f08c5392f756cdULL;
|
||||
|
||||
static const char table[128] = {
|
||||
0, 1, 12, 2, 13, 22, 17, 3,
|
||||
14, 33, 23, 36, 18, 58, 28, 4,
|
||||
62, 15, 34, 26, 24, 48, 50, 37,
|
||||
19, 55, 59, 52, 29, 44, 39, 5,
|
||||
63, 11, 21, 16, 32, 35, 57, 27,
|
||||
61, 25, 47, 49, 54, 51, 43, 38,
|
||||
10, 20, 31, 56, 60, 46, 53, 42,
|
||||
9, 30, 45, 41, 8, 40, 7, 6,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 52, 53, 54, 55, 56,
|
||||
57, 58, 59, 60, 61, 62, 63, 64
|
||||
};
|
||||
|
||||
int ctz4 (unsigned long x)
|
||||
{
|
||||
unsigned long lsb = x & -x;
|
||||
return table[(lsb * magic) >> 58];
|
||||
}
|
||||
|
||||
/* { dg-final { scan-tree-dump {= \.CTZ} "forwprop2" { target { { i?86-*-* x86_64-*-* } && { ! { ia32 } } } } } } */
|
||||
/* { dg-final { scan-tree-dump {= \.CTZ} "forwprop2" { target aarch64*-*-* } } } */
|
||||
/* { dg-final { scan-tree-dump {= \.CTZ} "forwprop2" { target { rv64 } } } } */
|
||||
/* { dg-final { scan-tree-dump {= \.CTZ} "forwprop2" { target { rv32 } } } } */
|
||||
/* { dg-final { scan-tree-dump {= \.CTZ} "forwprop2" { target { loongarch64*-*-* } } } } */
|
|
@ -2269,7 +2269,7 @@ check_ctz_array (tree ctor, unsigned HOST_WIDE_INT mulc,
|
|||
HOST_WIDE_INT &zero_val, unsigned shift, unsigned bits)
|
||||
{
|
||||
tree elt, idx;
|
||||
unsigned HOST_WIDE_INT i, mask;
|
||||
unsigned HOST_WIDE_INT i, mask, raw_idx = 0;
|
||||
unsigned matched = 0;
|
||||
|
||||
mask = ((HOST_WIDE_INT_1U << (bits - shift)) - 1) << shift;
|
||||
|
@ -2278,13 +2278,34 @@ check_ctz_array (tree ctor, unsigned HOST_WIDE_INT mulc,
|
|||
|
||||
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), i, idx, elt)
|
||||
{
|
||||
if (TREE_CODE (idx) != INTEGER_CST || TREE_CODE (elt) != INTEGER_CST)
|
||||
if (TREE_CODE (idx) != INTEGER_CST)
|
||||
return false;
|
||||
if (i > bits * 2)
|
||||
if (TREE_CODE (elt) != INTEGER_CST && TREE_CODE (elt) != RAW_DATA_CST)
|
||||
return false;
|
||||
|
||||
unsigned HOST_WIDE_INT index = tree_to_shwi (idx);
|
||||
HOST_WIDE_INT val = tree_to_shwi (elt);
|
||||
HOST_WIDE_INT val;
|
||||
|
||||
if (TREE_CODE (elt) == INTEGER_CST)
|
||||
val = tree_to_shwi (elt);
|
||||
else
|
||||
{
|
||||
if (raw_idx == (unsigned) RAW_DATA_LENGTH (elt))
|
||||
{
|
||||
raw_idx = 0;
|
||||
continue;
|
||||
}
|
||||
if (TYPE_UNSIGNED (TREE_TYPE (elt)))
|
||||
val = RAW_DATA_UCHAR_ELT (elt, raw_idx);
|
||||
else
|
||||
val = RAW_DATA_SCHAR_ELT (elt, raw_idx);
|
||||
index += raw_idx;
|
||||
raw_idx++;
|
||||
i--;
|
||||
}
|
||||
|
||||
if (index > bits * 2)
|
||||
return false;
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue