* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
@ 2024-03-01 4:59 ` pinskia at gcc dot gnu.org
2024-03-01 6:28 ` liuhongt at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-01 4:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
[apinski@xeond2 libstdc++-v3]$ c++filt --format dlang
_D4core8lifetime__T12_d_newclassTTC1a14BreakStatementZQBjFNaNbNeZQBf
core.lifetime._d_newclassT!(a.BreakStatement)._d_newclassT()
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
2024-03-01 4:59 ` [Bug d/114171] " pinskia at gcc dot gnu.org
@ 2024-03-01 6:28 ` liuhongt at gcc dot gnu.org
2024-03-01 7:05 ` rguenth at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-03-01 6:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
Hongtao Liu <liuhongt at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |liuhongt at gcc dot gnu.org
Last reconfirmed| |2024-3-1
--- Comment #2 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
on rtl level,we get
(insn 7 6 8 2 (set (reg:CCZ 17 flags)
(compare:CCZ (mem:TI (plus:DI (reg/f:DI 100 [ _5 ])
(const_int 24 [0x18])) [0 MEM[(ucent *)_5 + 24B]+0 S16
A128])
(const_int 0 [0]))) "test.d":15:16 30 {*cmpti_doubleword}
(nil))
It's 16-byte aligned.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
2024-03-01 4:59 ` [Bug d/114171] " pinskia at gcc dot gnu.org
2024-03-01 6:28 ` liuhongt at gcc dot gnu.org
@ 2024-03-01 7:05 ` rguenth at gcc dot gnu.org
2024-03-01 8:38 ` a.horodniceanu at proton dot me
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-01 7:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.3
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (2 preceding siblings ...)
2024-03-01 7:05 ` rguenth at gcc dot gnu.org
@ 2024-03-01 8:38 ` a.horodniceanu at proton dot me
2024-03-01 13:25 ` ibuclaw at gdcproject dot org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: a.horodniceanu at proton dot me @ 2024-03-01 8:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #3 from Andrei Horodniceanu <a.horodniceanu at proton dot me> ---
(In reply to Hongtao Liu from comment #2)
> on rtl level,we get
>
> (insn 7 6 8 2 (set (reg:CCZ 17 flags)
> (compare:CCZ (mem:TI (plus:DI (reg/f:DI 100 [ _5 ])
> (const_int 24 [0x18])) [0 MEM[(ucent *)_5 + 24B]+0 S16
> A128])
> (const_int 0 [0]))) "test.d":15:16 30 {*cmpti_doubleword}
> (nil))
>
> It's 16-byte aligned.
I'm not sure I understand this notation but I think I can pick the mem function
which returns a memory reference at the offset given by the _5 register? plus
24 of 16 byte size and 128 bit alignment. This does match up as the size of the
BreakStatement class is 40 (24 + 16). I don't see how it can say that that
memory is 16-byte aligned as in D code the alignment of the class is 8 but it
may be just that, internally, gcc has a more accurate record.
Could you check the rtl for the same snippet of code but instead of `interface
ASTNode` do `abstract class ASTNode`? This would make BreakStatement be of size
32 instead of 40 and change the 24 offset to 16 which happens to produce a
16-byte aligned memory location. This is the only other interesting thing I hit
when trying to reduce the failing code.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (3 preceding siblings ...)
2024-03-01 8:38 ` a.horodniceanu at proton dot me
@ 2024-03-01 13:25 ` ibuclaw at gdcproject dot org
2024-03-01 13:37 ` rguenth at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ibuclaw at gdcproject dot org @ 2024-03-01 13:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #4 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Removed druntime dependency.
---
import gcc.builtins;
struct Token {
string label;
}
struct BreakStatement {
ulong pad;
Token label;
}
pragma(inline, false)
auto newclass()
{
void *p = __builtin_malloc(BreakStatement.sizeof);
__builtin_memset(p, 0, BreakStatement.sizeof);
return cast(BreakStatement*) p;
}
int main ()
{
auto bn = newclass();
return bn.label is Token.init;
}
---
Roughly the equivalent C++
---
struct Token {
struct {
__SIZE_TYPE__ length;
const char *ptr;
} label;
};
struct BreakStatement {
__UINT64_TYPE__ pad;
Token label;
};
__attribute__((noinline))
BreakStatement *newclass()
{
void *p = __builtin_malloc(sizeof(BreakStatement));
__builtin_memset(p, 0, sizeof(BreakStatement));
return (BreakStatement*) p;
}
int main ()
{
auto bn = newclass();
auto init = Token();
return *(__uint128_t*)&bn->label == *(__uint128_t*)&init;
}
---
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (4 preceding siblings ...)
2024-03-01 13:25 ` ibuclaw at gdcproject dot org
@ 2024-03-01 13:37 ` rguenth at gcc dot gnu.org
2024-03-01 14:13 ` ibuclaw at gdcproject dot org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-01 13:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Iain Buclaw from comment #4)
> Removed druntime dependency.
> ---
> import gcc.builtins;
> struct Token {
> string label;
> }
> struct BreakStatement {
> ulong pad;
> Token label;
> }
>
> pragma(inline, false)
> auto newclass()
> {
> void *p = __builtin_malloc(BreakStatement.sizeof);
> __builtin_memset(p, 0, BreakStatement.sizeof);
> return cast(BreakStatement*) p;
> }
>
> int main ()
> {
> auto bn = newclass();
> return bn.label is Token.init;
> }
> ---
>
>
>
> Roughly the equivalent C++
> ---
> struct Token {
> struct {
> __SIZE_TYPE__ length;
> const char *ptr;
> } label;
> };
> struct BreakStatement {
> __UINT64_TYPE__ pad;
> Token label;
> };
>
> __attribute__((noinline))
> BreakStatement *newclass()
> {
> void *p = __builtin_malloc(sizeof(BreakStatement));
> __builtin_memset(p, 0, sizeof(BreakStatement));
> return (BreakStatement*) p;
> }
>
> int main ()
> {
> auto bn = newclass();
> auto init = Token();
> return *(__uint128_t*)&bn->label == *(__uint128_t*)&init;
> }
> ---
Unless gdc somehow guarantees bn->label and init are 128bit aligned
then "casting" this way is broken. You can of course use
build_aligned_type to build a properly (mis-)aligned type to use
to dereference to.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (5 preceding siblings ...)
2024-03-01 13:37 ` rguenth at gcc dot gnu.org
@ 2024-03-01 14:13 ` ibuclaw at gdcproject dot org
2024-03-03 1:33 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ibuclaw at gdcproject dot org @ 2024-03-01 14:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #6 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
(In reply to Richard Biener from comment #5)
> Unless gdc somehow guarantees bn->label and init are 128bit aligned
> then "casting" this way is broken. You can of course use
> build_aligned_type to build a properly (mis-)aligned type to use
> to dereference to.
Right, it looks like the lowering for struct comparisons wasn't taking the
original alignment into account when doing identity comparisons of struct-like
fields.
---
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1006,6 +1006,7 @@ lower_struct_comparison (tree_code code,
StructDeclaration *sd,
if (tmode == NULL_TREE)
tmode = make_unsigned_type (GET_MODE_BITSIZE (mode.require
()));
+ tmode = build_aligned_type (tmode, TYPE_ALIGN (stype));
t1ref = build_vconvert (tmode, t1ref);
t2ref = build_vconvert (tmode, t2ref);
---
The above change gets reflected in the generated assembly.
---
@@ -326,7 +326,7 @@ _Dmain:
subq $8, %rsp
.cfi_def_cfa_offset 16
call _D8pr1141718newclassFNbNiZPSQBa14BreakStatement
- vmovdqa 8(%rax), %xmm0
+ vmovdqu 8(%rax), %xmm0
xorl %eax, %eax
vptest %xmm0, %xmm0
sete %al
---
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (6 preceding siblings ...)
2024-03-01 14:13 ` ibuclaw at gdcproject dot org
@ 2024-03-03 1:33 ` cvs-commit at gcc dot gnu.org
2024-03-03 1:35 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-03 1:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:623f52775e677bb3d6e9e7ef97196741dd904b1e
commit r14-9277-g623f52775e677bb3d6e9e7ef97196741dd904b1e
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Sun Mar 3 02:26:37 2024 +0100
d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
PR d/114171
gcc/d/ChangeLog:
* d-codegen.cc (lower_struct_comparison): Keep alignment of
original
type in reinterpret cast for comparison.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr114171.d: New test.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (7 preceding siblings ...)
2024-03-03 1:33 ` cvs-commit at gcc dot gnu.org
@ 2024-03-03 1:35 ` cvs-commit at gcc dot gnu.org
2024-03-03 1:37 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-03 1:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:cdcbc56c3f5a04e4e7cccdc70a420bc069a0941f
commit r13-8401-gcdcbc56c3f5a04e4e7cccdc70a420bc069a0941f
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Sun Mar 3 02:26:37 2024 +0100
d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
PR d/114171
gcc/d/ChangeLog:
* d-codegen.cc (lower_struct_comparison): Keep alignment of
original
type in reinterpret cast for comparison.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr114171.d: New test.
(cherry picked from commit 623f52775e677bb3d6e9e7ef97196741dd904b1e)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (8 preceding siblings ...)
2024-03-03 1:35 ` cvs-commit at gcc dot gnu.org
@ 2024-03-03 1:37 ` cvs-commit at gcc dot gnu.org
2024-03-03 1:39 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-03 1:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:ff9d13e0110b46b39cacb431926515cf4be3aa8d
commit r12-10191-gff9d13e0110b46b39cacb431926515cf4be3aa8d
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Sun Mar 3 02:26:37 2024 +0100
d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
PR d/114171
gcc/d/ChangeLog:
* d-codegen.cc (lower_struct_comparison): Keep alignment of
original
type in reinterpret cast for comparison.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr114171.d: New test.
(cherry picked from commit 623f52775e677bb3d6e9e7ef97196741dd904b1e)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (9 preceding siblings ...)
2024-03-03 1:37 ` cvs-commit at gcc dot gnu.org
@ 2024-03-03 1:39 ` cvs-commit at gcc dot gnu.org
2024-03-03 1:39 ` ibuclaw at gdcproject dot org
2024-08-16 2:53 ` sjames at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-03 1:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:3e60064a03a1a6d38ceb5ca4eb7e1f4d30a8aed1
commit r11-11266-g3e60064a03a1a6d38ceb5ca4eb7e1f4d30a8aed1
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Sun Mar 3 02:26:37 2024 +0100
d: Fix gdc -O2 -mavx generates misaligned vmovdqa instruction [PR114171]
PR d/114171
gcc/d/ChangeLog:
* d-codegen.cc (lower_struct_comparison): Keep alignment of
original
type in reinterpret cast for comparison.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr114171.d: New test.
(cherry picked from commit 623f52775e677bb3d6e9e7ef97196741dd904b1e)
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (10 preceding siblings ...)
2024-03-03 1:39 ` cvs-commit at gcc dot gnu.org
@ 2024-03-03 1:39 ` ibuclaw at gdcproject dot org
2024-08-16 2:53 ` sjames at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: ibuclaw at gdcproject dot org @ 2024-03-03 1:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
Iain Buclaw <ibuclaw at gdcproject dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #11 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Fix committed and backported.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug d/114171] [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction
2024-02-29 15:53 [Bug d/114171] New: [13/14 Regression] gdc -O2 -mavx generates misaligned vmovdqa instruction a.horodniceanu at proton dot me
` (11 preceding siblings ...)
2024-03-03 1:39 ` ibuclaw at gdcproject dot org
@ 2024-08-16 2:53 ` sjames at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-08-16 2:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.3 |11.5
^ permalink raw reply [flat|nested] 14+ messages in thread