PPC64 codgen issue when passing structure parameters by value
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.
@llvm/issue-subscribers-backend-powerpc
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
Proposed fix in https://reviews.llvm.org/D133338
@llvm/issue-subscribers-clang-codegen