mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 21:56:04 +00:00

Set the writable and dead_on_unwind attributes for sret arguments. These indicate that the argument points to writable memory (and it's legal to introduce spurious writes to it on entry to the function) and that the argument memory will not be used if the call unwinds. This enables additional MemCpyOpt/DSE/LICM optimizations.
45 lines
1.6 KiB
C++
45 lines
1.6 KiB
C++
// RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm %s -o - | FileCheck %s
|
|
|
|
// PR15768
|
|
|
|
// A trivial 20 byte struct is returned indirectly and taken as byval.
|
|
struct S {
|
|
S();
|
|
int a, b, c, d, e;
|
|
};
|
|
|
|
struct C {
|
|
S variadic_sret(const char *f, ...);
|
|
S __cdecl cdecl_sret();
|
|
S __cdecl byval_and_sret(S a);
|
|
int c;
|
|
};
|
|
|
|
S C::variadic_sret(const char *f, ...) { return S(); }
|
|
S C::cdecl_sret() { return S(); }
|
|
S C::byval_and_sret(S a) { return S(); }
|
|
|
|
// CHECK: define dso_local void @"?variadic_sret@C@@QAA?AUS@@PBDZZ"(ptr {{[^,]*}} %this, ptr dead_on_unwind noalias writable sret(%struct.S) align 4 %agg.result, ptr noundef %f, ...)
|
|
// CHECK: define dso_local void @"?cdecl_sret@C@@QAA?AUS@@XZ"(ptr {{[^,]*}} %this, ptr dead_on_unwind noalias writable sret(%struct.S) align 4 %agg.result)
|
|
// CHECK: define dso_local void @"?byval_and_sret@C@@QAA?AUS@@U2@@Z"(ptr {{[^,]*}} %this, ptr dead_on_unwind noalias writable sret(%struct.S) align 4 %agg.result, ptr noundef byval(%struct.S) align 4 %a)
|
|
|
|
int main() {
|
|
C c;
|
|
c.variadic_sret("asdf");
|
|
c.cdecl_sret();
|
|
c.byval_and_sret(S());
|
|
}
|
|
// CHECK-LABEL: define dso_local noundef i32 @main()
|
|
// CHECK: call void {{.*}} @"?variadic_sret@C@@QAA?AUS@@PBDZZ"
|
|
// CHECK: call void @"?cdecl_sret@C@@QAA?AUS@@XZ"
|
|
// CHECK: call void @"?byval_and_sret@C@@QAA?AUS@@U2@@Z"
|
|
|
|
// __fastcall has similar issues.
|
|
struct A {
|
|
S __fastcall f(int x);
|
|
};
|
|
S A::f(int x) {
|
|
return S();
|
|
}
|
|
// CHECK-LABEL: define dso_local x86_fastcallcc void @"?f@A@@QAI?AUS@@H@Z"(ptr inreg noundef nonnull align 1 dereferenceable(1) %this, ptr dead_on_unwind inreg noalias writable sret(%struct.S) align 4 %agg.result, i32 noundef %x)
|