llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

PPC64 codgen issue when passing structure parameters by value

Open ltertan opened this issue 4 years ago • 4 comments

Compile options:

--target=ppc64 -mcpu=a2 -O2

Test-case:

#include <stdio.h>
#include <stdarg.h>

typedef struct { char c; } myStruct;

int test_check(int i, ...) {
        myStruct mS;
        va_list ap;

        va_start(ap, i);
        mS = va_arg(ap, myStruct);
        va_end(ap);
        return (int)(mS.c+i);
}

int main (void) {
        volatile int i = 0;

        myStruct mS = { 5 };
        i = test_check(1, mS);
        if (i == 6) printf("Passed\n"); else printf("Failed\n");

        return 0;
}

Description:

In big-endian mode, the generated instructions for the mS = va_arg(ap, myStruct) line are wrong:

        std 4, 56(1)
        lbz 4, 56(1)

The compiler should generate a load with an offset of 7 for this, based on r4, for big endian. The code for little endian looks good.

ltertan avatar Jun 06 '22 16:06 ltertan

@llvm/issue-subscribers-backend-powerpc

llvmbot avatar Jun 06 '22 16:06 llvmbot

Problem with lowering the @llvm.memcpy.p0i8.p0i8.i64 intrinsic and endianness should be taken care here i.e

%8 = bitcast i8* %6 to %struct.myStruct*, !dbg !33 %9 = bitcast %struct.myStruct* %3 to i8*, !dbg !33 %10 = bitcast %struct.myStruct* %8 to i8*, !dbg !33 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %9, i8* align 8 %10, i64 1, i1 false), !dbg !33

ukalappa-mips avatar Aug 25 '22 11:08 ukalappa-mips

Proposed fix in https://reviews.llvm.org/D133338

orcguru avatar Sep 06 '22 07:09 orcguru

@llvm/issue-subscribers-clang-codegen

llvmbot avatar Oct 17 '22 03:10 llvmbot