public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111779] New: Fail to vectorize the struct include struct
@ 2023-10-12 7:31 juzhe.zhong at rivai dot ai
2023-10-12 8:45 ` [Bug tree-optimization/111779] " rguenth at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: juzhe.zhong at rivai dot ai @ 2023-10-12 7:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111779
Bug ID: 111779
Summary: Fail to vectorize the struct include struct
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: juzhe.zhong at rivai dot ai
Target Milestone: ---
#include <stdbool.h>
#include <assert.h>
struct C
{
int c;
int d;
bool f :1;
float e;
};
struct A
{
unsigned int a;
unsigned char c1, c2;
bool b1 : 1;
bool b2 : 1;
bool b3 : 1;
struct C b4;
};
void
foo (const struct A * __restrict x, int y)
{
int s = 0, i = 0;
for (i = 0; i < y; ++i)
{
const struct A a = x[i];
s += a.b4.f ? 1 : 0;
}
assert (s == 0);
//__builtin_abort ();
}
int
main ()
{
struct A x[100];
int i;
__builtin_memset (x, -1, sizeof (x));
for (i = 0; i < 100; i++)
{
x[i].b1 = false;
x[i].b2 = false;
x[i].b3 = false;
x[i].b4.f = false;
}
foo (x, 100);
return 0;
}
https://godbolt.org/z/KWb7c1n5h
Both SVE GCC and RVV GCC failed to vectorize it.
But Clang succeed on vectorization.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/111779] Fail to vectorize the struct include struct
2023-10-12 7:31 [Bug c/111779] New: Fail to vectorize the struct include struct juzhe.zhong at rivai dot ai
@ 2023-10-12 8:45 ` rguenth at gcc dot gnu.org
2023-10-12 9:17 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-12 8:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111779
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c |tree-optimization
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
CC| |jamborm at gcc dot gnu.org
Last reconfirmed| |2023-10-12
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is the aggregate copy:
t.c:26:22: missed: not vectorized: more than one data ref in stmt: a = *_3;
which SRA fails to scalarize:
<bb 3> [local count: 955630224]:
# s_23 = PHI <s_18(3), 0(2)>
# i_25 = PHI <i_20(3), 0(2)>
_1 = (long unsigned int) i_25;
_2 = _1 * 24;
_3 = x_16(D) + _2;
a = *_3;
_4 = BIT_FIELD_REF <a.b4, 8, 64>;
_12 = _4 & 1;
_6 = (int) _12;
s_18 = _6 + s_23;
a ={v} {CLOBBER(eol)};
i_20 = i_25 + 1;
if (y_14(D) > i_20)
Candidate (2778): a
...
! Disqualifying a - No scalar replacements to be created.
the BIT_FIELD_REF is already created by early folding in
optimize_bit_field_compare folding (int) a.b4.f != 0
s = ((int) NON_LVALUE_EXPR <BIT_FIELD_REF <a.b4, 8, 64>> & 1) + s;
SRA could handle BIT_FIELD_REFs just fine - esp. quantities with
a byte size. And then this folding is just premature...
Removing the folding that handles BF != CST fixes it. I know removing
all of it, esp. BF != BF will regress some stuff. I'll put this half-way
patch through testing.
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 82299bb7f1d..3db383360d6 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -4695,7 +4695,7 @@ optimize_bit_field_compare (location_t loc, enum
tree_code code,
return 0;
if (const_p)
- rreversep = lreversep;
+ return 0;
else
{
/* If this is not a constant, we can only do something if bit positions,
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/111779] Fail to vectorize the struct include struct
2023-10-12 7:31 [Bug c/111779] New: Fail to vectorize the struct include struct juzhe.zhong at rivai dot ai
2023-10-12 8:45 ` [Bug tree-optimization/111779] " rguenth at gcc dot gnu.org
@ 2023-10-12 9:17 ` rguenth at gcc dot gnu.org
2023-10-12 10:45 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-12 9:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111779
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=108070
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ah, did that already, it regressed, I filed PR108070 for it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/111779] Fail to vectorize the struct include struct
2023-10-12 7:31 [Bug c/111779] New: Fail to vectorize the struct include struct juzhe.zhong at rivai dot ai
2023-10-12 8:45 ` [Bug tree-optimization/111779] " rguenth at gcc dot gnu.org
2023-10-12 9:17 ` rguenth at gcc dot gnu.org
@ 2023-10-12 10:45 ` rguenth at gcc dot gnu.org
2023-10-13 6:34 ` cvs-commit at gcc dot gnu.org
2023-10-13 6:47 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-12 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111779
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I posted a patch for SRA.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/111779] Fail to vectorize the struct include struct
2023-10-12 7:31 [Bug c/111779] New: Fail to vectorize the struct include struct juzhe.zhong at rivai dot ai
` (2 preceding siblings ...)
2023-10-12 10:45 ` rguenth at gcc dot gnu.org
@ 2023-10-13 6:34 ` cvs-commit at gcc dot gnu.org
2023-10-13 6:47 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-13 6:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111779
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:6decda1a35be5764101987c210b5693a0d914e58
commit r14-4612-g6decda1a35be5764101987c210b5693a0d914e58
Author: Richard Biener <rguenther@suse.de>
Date: Thu Oct 12 11:34:57 2023 +0200
tree-optimization/111779 - Handle some BIT_FIELD_REFs in SRA
The following handles byte-aligned, power-of-two and byte-multiple
sized BIT_FIELD_REF reads in SRA. In particular this should cover
BIT_FIELD_REFs created by optimize_bit_field_compare.
For gcc.dg/tree-ssa/ssa-dse-26.c we now SRA the BIT_FIELD_REF
appearing there leading to more DSE, fully eliding the aggregates.
This results in the same false positive -Wuninitialized as the
older attempt to remove the folding from optimize_bit_field_compare,
fixed by initializing part of the aggregate unconditionally.
PR tree-optimization/111779
gcc/
* tree-sra.cc (sra_handled_bf_read_p): New function.
(build_access_from_expr_1): Handle some BIT_FIELD_REFs.
(sra_modify_expr): Likewise.
(make_fancy_name_1): Skip over BIT_FIELD_REF.
gcc/fortran/
* trans-expr.cc (gfc_trans_assignment_1): Initialize
lhs_caf_attr and rhs_caf_attr codimension flag to avoid
false positive -Wuninitialized.
gcc/testsuite/
* gcc.dg/tree-ssa/ssa-dse-26.c: Adjust for more DSE.
* gcc.dg/vect/vect-pr111779.c: New testcase.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/111779] Fail to vectorize the struct include struct
2023-10-12 7:31 [Bug c/111779] New: Fail to vectorize the struct include struct juzhe.zhong at rivai dot ai
` (3 preceding siblings ...)
2023-10-13 6:34 ` cvs-commit at gcc dot gnu.org
@ 2023-10-13 6:47 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-13 6:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111779
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
This should be fixed now.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-13 6:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 7:31 [Bug c/111779] New: Fail to vectorize the struct include struct juzhe.zhong at rivai dot ai
2023-10-12 8:45 ` [Bug tree-optimization/111779] " rguenth at gcc dot gnu.org
2023-10-12 9:17 ` rguenth at gcc dot gnu.org
2023-10-12 10:45 ` rguenth at gcc dot gnu.org
2023-10-13 6:34 ` cvs-commit at gcc dot gnu.org
2023-10-13 6:47 ` rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).