https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103095

            Bug ID: 103095
           Summary: Option to force no overalignment
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider gdb test-case gdb/testsuite/gdb.arch/i386-avx.c.

It contains assembly doing:
...
  asm ("vmovaps 0(%0), %%ymm0\n\t"
       "vmovaps 32(%0), %%ymm1\n\t"
       "vmovaps 64(%0), %%ymm2\n\t"
       "vmovaps 96(%0), %%ymm3\n\t"
       "vmovaps 128(%0), %%ymm4\n\t"
       "vmovaps 160(%0), %%ymm5\n\t"
       "vmovaps 192(%0), %%ymm6\n\t"
       "vmovaps 224(%0), %%ymm7\n\t"
       : /* no output operands */
       : "r" (data)
       : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7");
...
where data is an v8sf_t array, which is defined as:
...
typedef struct {
  float f[8];
} v8sf_t;
...

The vmovaps insn requires the memory operand to be 32-byte aligned, but the
data variable is required to be only float (4 byte) aligned.

However, the test-case passes for me, with a variety of gcc compilers for 4.8.5
to 11.2.1, because the actual alignment turns out to be sufficient.

But when running with clang it happens to fail because the actual alignment
turns out to be not sufficient.

It would be nice if we'd have a gcc compiler option that flushes out these
problems deterministically, by ensuring that variables have the required
alignment, but not more than that.

That is, say we have a float variable f of size 4 and alignment 4.  We'd want
to allocate 8 bytes for it, 8-byte aligned, and then place the variable in the
second half.  That way we've ensured that the variable is 4-byte aligned, but
not 8-byte aligned.

This may require changes in compiler and/or assembler and/or linker.

Reply via email to