617: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) 61e: 00 00 ... $ objdump -d t1-clang ... 0000000000400480
40049f: 90 nop ...
Closed Quuxplusone closed 3 years ago
Bugzilla Link | PR50943 |
Status | RESOLVED INVALID |
Importance | P enhancement |
Reported by | Paul Robinson (paul_robinson@playstation.sony.com) |
Reported on | 2021-06-30 08:51:15 -0700 |
Last modified on | 2021-06-30 10:57:34 -0700 |
Version | trunk |
Hardware | PC Linux |
CC | andrea.dibiagio@gmail.com, craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
$ objdump -d t1-gcc
...
00000000000005fa
617: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
61e: 00 00
...
$ objdump -d t1-clang
...
0000000000400480
40049f: 90 nop
...
gcc sets up the address of data
as
605: 48 8d 05 14 0a 20 00 lea 0x200a14(%rip),%rax
while clang produces
400492: b8 30 10 60 00 mov $0x601030,%eax
I suspect that there is an alignment problem here. If clang is not aligning the array to 32-bytes, then it is a problem for the VMOVAPS.
Out of curiosity, I have built the reproducible posted by Paul on compiler explorer.
I noticed that the array is emitted by clang with assembler directive
.p2align 4
That directive only enforces a 16-byte alignment. Unfortunately the VMOVAPS from that code expects the operand to be aligned on a 32-byte boundary.
GCC, on the other hand, explicitly aligns the array to a 32-byte boundary using the following assembly directive:
.align 32
I mentioned this to Paul, and I have suggested as an experiment to replace the VMOVAPS with VMOVUPS. That was enough to fix his crash.
So, I guess that there may be a problem with the alignment set by clang for that array.
I'm not sure there's an alignment requirement for that array other than what is implied by float. Versions of gcc prior to 5 use align 16 with -Os and align 32 with -O2.
Adding attribute ((aligned (32))) to the struct definition also appears to fix the crash.
(In reply to Craig Topper from comment #3)
> I'm not sure there's an alignment requirement for that array other than what
> is implied by float. Versions of gcc prior to 5 use align 16 with -Os and
> align 32 with -O2.
>
> Adding __attribute__ ((aligned (32))) to the struct definition also appears
> to fix the crash.
I was coming to the same conclusion. I threw in some alignof() expressions
and they all report 4. Pumping up the alignment in the generated code seems
rather optional.
I'll resolve this as invalid and we'll patch the test to enforce the required
alignment.