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

            Bug ID: 112613
           Summary: gcc generates incorrect argument reads at prologue
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

This is an example extracted from an attempt to debug PR112572.

Attached file is not directly executable. And it's not easy to amoend to make
it executable, but I think it illustrates the problem well:

For the following function in the source file:


__attribute__((noipa))
void X86InterleavedAccessGroup::decompose(
 Instruction *VecInst, unsigned NumSubVectors, FixedVectorType *SubVecTy,
 SmallVectorImpl<Instruction *> &DecomposedVectors) {
 if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(VecInst)) {
...

gcc generates the following prologue:


$ gcc/xg++ -Bgcc -O2 -march=znver2 -fno-checking -fno-lifetime-dse -std=c++17
-S /tmp/bug.cpp -o - -fPIE
...
_ZN1n25X86InterleavedAccessGroup9decomposeEPN4llvm11InstructionEjPNS1_15FixedVectorTypeERNS1_15SmallVectorImplIS3_EE:
.LFB19440:
        .cfi_startproc
        .cfi_personality 0x9b,DW.ref.__gxx_personality_v0
        .cfi_lsda 0x1b,.LLSDA19440
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        pushq   %r15
        pushq   %r14
        pushq   %r13
        pushq   %r12
        pushq   %rbx
        .cfi_offset 15, -24
        .cfi_offset 14, -32
        .cfi_offset 13, -40
        .cfi_offset 12, -48
        .cfi_offset 3, -56
        movl    %edx, %r12d
        movq    %r8, %rbx
        subq    $328, %rsp
        cmpb    $91, 16(%r14) // <- what is %r14? it should be %rsi
...

I think %r14 is an invalid value. It should be something like %rsi (that's what
-fno-PIE does).

I hope this example is analysable to get the idea why this register is chosen.

$ gcc/xg++ -Bgcc -v
Reading specs from gcc/specs
COLLECT_GCC=gcc/xg++
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--disable-bootstrap --disable-lto --disable-libsanitizer
--disable-libstdcxx-pch --enable-languages=c,c++ --disable-libgomp
--disable-libquadmath --disable-libvtv CFLAGS='-O1 -g0' CXXFLAGS='-O1 -g0'
LDFLAGS='-O1 -g0'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20231118 (experimental) (GCC)

Reply via email to