| // RUN: %clang_cc1 -triple mipsel-unknown-linux -O3 -o - -emit-llvm %s | FileCheck %s -check-prefix=O32 |
| // RUN: %clang_cc1 -triple mips64el-unknown-linux -O3 -target-abi n64 -o - -emit-llvm %s | FileCheck %s -check-prefix=N64 |
| // RUN: %clang_cc1 -triple mipsel-unknown-linux -target-feature "+fp64" -O3 -o - -emit-llvm %s | FileCheck %s -check-prefix=O32 |
| |
| typedef struct { |
| double d; |
| long double ld; |
| } S0; |
| |
| // Insert padding to ensure arguments of type S0 are aligned to 16-byte boundaries. |
| |
| // N64-LABEL: define{{.*}} void @foo1(i32 noundef signext %a0, i64 %0, double inreg %a1.coerce0, i64 inreg %a1.coerce1, i64 inreg %a1.coerce2, i64 inreg %a1.coerce3, double inreg %a2.coerce0, i64 inreg %a2.coerce1, i64 inreg %a2.coerce2, i64 inreg %a2.coerce3, i32 noundef signext %b, i64 %1, double inreg %a3.coerce0, i64 inreg %a3.coerce1, i64 inreg %a3.coerce2, i64 inreg %a3.coerce3) |
| // N64: tail call void @foo2(i32 noundef signext 1, i32 noundef signext 2, i32 noundef signext %a0, i64 undef, double inreg %a1.coerce0, i64 inreg %a1.coerce1, i64 inreg %a1.coerce2, i64 inreg %a1.coerce3, double inreg %a2.coerce0, i64 inreg %a2.coerce1, i64 inreg %a2.coerce2, i64 inreg %a2.coerce3, i32 noundef signext 3, i64 undef, double inreg %a3.coerce0, i64 inreg %a3.coerce1, i64 inreg %a3.coerce2, i64 inreg %a3.coerce3) |
| // N64: declare void @foo2(i32 noundef signext, i32 noundef signext, i32 noundef signext, i64, double inreg, i64 inreg, i64 inreg, i64 inreg, double inreg, i64 inreg, i64 inreg, i64 inreg, i32 noundef signext, i64, double inreg, i64 inreg, i64 inreg, i64 inreg) |
| |
| extern void foo2(int, int, int, S0, S0, int, S0); |
| |
| void foo1(int a0, S0 a1, S0 a2, int b, S0 a3) { |
| foo2(1, 2, a0, a1, a2, 3, a3); |
| } |
| |
| // Insert padding before long double argument. |
| // |
| // N64-LABEL: define{{.*}} void @foo3(i32 noundef signext %a0, i64 %0, fp128 noundef %a1) |
| // N64: tail call void @foo4(i32 noundef signext 1, i32 noundef signext 2, i32 noundef signext %a0, i64 undef, fp128 noundef %a1) |
| // N64: declare void @foo4(i32 noundef signext, i32 noundef signext, i32 noundef signext, i64, fp128 noundef) |
| |
| extern void foo4(int, int, int, long double); |
| |
| void foo3(int a0, long double a1) { |
| foo4(1, 2, a0, a1); |
| } |
| |
| // Insert padding after hidden argument. |
| // |
| // N64-LABEL: define{{.*}} void @foo5(ptr dead_on_unwind noalias writable sret(%struct.S0) align 16 %agg.result, i64 %0, fp128 noundef %a0) |
| // N64: call void @foo6(ptr dead_on_unwind writable sret(%struct.S0) align 16 %agg.result, i32 noundef signext 1, i32 noundef signext 2, i64 undef, fp128 noundef %a0) |
| // N64: declare void @foo6(ptr dead_on_unwind writable sret(%struct.S0) align 16, i32 noundef signext, i32 noundef signext, i64, fp128 noundef) |
| |
| extern S0 foo6(int, int, long double); |
| |
| S0 foo5(long double a0) { |
| return foo6(1, 2, a0); |
| } |
| |
| #ifdef __SIZEOF_INT128__ |
| // Insert padding before a 128-bit integer argument, which is 16-byte aligned, to make it start in an even-numbered register. |
| // |
| // N64-LABEL: define{{.*}} void @foo11(i32 noundef signext %a0, i64 %0, i128 noundef signext %a1) |
| // N64: tail call void @foo12(i32 noundef signext 1, i32 noundef signext 2, i32 noundef signext %a0, i64 undef, i128 noundef signext %a1) |
| // N64: declare void @foo12(i32 noundef signext, i32 noundef signext, i32 noundef signext, i64, i128 noundef signext) |
| |
| extern void foo12(int, int, int, __int128); |
| |
| void foo11(int a0, __int128 a1) { |
| foo12(1, 2, a0, a1); |
| } |
| |
| // Do not insert padding if the 128-bit integer is already 16-byte aligned. |
| // Hence foo13 needs padding but foo14 does not. |
| // |
| // N64-LABEL: define{{.*}} void @foo13(i32 noundef signext %a0, i64 %0, i128 noundef zeroext %a1) |
| // N64: tail call void @foo14(i32 noundef signext 1, i32 noundef signext %a0, i128 noundef zeroext %a1) |
| // N64: declare void @foo14(i32 noundef signext, i32 noundef signext, i128 noundef zeroext) |
| |
| extern void foo14(int, int, unsigned __int128); |
| |
| void foo13(int a0, unsigned __int128 a1) { |
| foo14(1, a0, a1); |
| } |
| |
| // Test a case where all but one argument register is exhausted. |
| // The padding is still inserted, and the full __int128 value is |
| // passed via the stack, it is not split. |
| // |
| // N64-LABEL: define{{.*}} void @foo15(i64 noundef signext %a0, i64 noundef signext %a1, i64 noundef signext %a2, i64 noundef signext %a3, i64 noundef signext %a4, i64 noundef signext %a5, i64 noundef signext %a6, i64 %0, i128 noundef signext %a7) |
| // N64: tail call void @foo16(i64 noundef signext %a0, i64 noundef signext %a1, i64 noundef signext %a2, i64 noundef signext %a3, i64 noundef signext %a4, i64 noundef signext %a5, i64 noundef signext %a6, i64 undef, i128 noundef signext %a7) |
| // N64: declare void @foo16(i64 noundef signext, i64 noundef signext, i64 noundef signext, i64 noundef signext, i64 noundef signext, i64 noundef signext, i64 noundef signext, i64, i128 noundef signext) |
| |
| extern void foo16(long, long, long, long, long, long, long, __int128); |
| |
| void foo15(long a0, long a1, long a2, long a3, long a4, long a5, long a6, __int128 a7) { |
| foo16(a0, a1, a2, a3, a4, a5, a6, a7); |
| } |
| #endif |
| |
| // Do not insert padding if ABI is O32. |
| // |
| // O32-LABEL: define{{.*}} void @foo7(float noundef %a0, double noundef %a1) |
| // O32: declare void @foo8(float noundef, double noundef) |
| |
| extern void foo8(float, double); |
| |
| void foo7(float a0, double a1) { |
| foo8(a0 + 1.0f, a1 + 2.0); |
| } |
| |
| // O32-LABEL: define{{.*}} void @foo9() |
| // O32: declare void @foo10(i32 noundef signext, i32 |
| |
| typedef struct __attribute__((aligned(16))) { |
| int a; |
| } S16; |
| |
| S16 s16; |
| |
| void foo10(int, S16); |
| |
| void foo9(void) { |
| foo10(1, s16); |
| } |
| |