1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes 2; In PR41658, argpromotion put an inalloca in a position that per the 3; calling convention is passed in a register. This test verifies that 4; we don't do that anymore. It also verifies that the combination of 5; globalopt and argpromotion is able to optimize the call safely. 6; 7; RUN: opt -S -argpromotion %s | FileCheck %s --check-prefix=ARGPROMOTION 8; RUN: opt -S -globalopt -argpromotion %s | FileCheck %s --check-prefix=GLOBALOPT_ARGPROMOTION 9 10target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" 11target triple = "i386-pc-windows-msvc19.11.0" 12 13%struct.a = type { i8 } 14 15define internal x86_thiscallcc void @internalfun(%struct.a* %this, <{ %struct.a }>* inalloca) { 16; ARGPROMOTION-LABEL: define {{[^@]+}}@internalfun 17; ARGPROMOTION-SAME: (%struct.a* [[THIS:%.*]], <{ [[STRUCT_A:%.*]] }>* inalloca [[TMP0:%.*]]) 18; ARGPROMOTION-NEXT: entry: 19; ARGPROMOTION-NEXT: [[A:%.*]] = getelementptr inbounds <{ [[STRUCT_A]] }>, <{ [[STRUCT_A]] }>* [[TMP0]], i32 0, i32 0 20; ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A]] }>, align 4 21; ARGPROMOTION-NEXT: [[TMP1:%.*]] = getelementptr inbounds <{ [[STRUCT_A]] }>, <{ [[STRUCT_A]] }>* [[ARGMEM]], i32 0, i32 0 22; ARGPROMOTION-NEXT: [[CALL:%.*]] = call x86_thiscallcc %struct.a* @copy_ctor(%struct.a* [[TMP1]], %struct.a* dereferenceable(1) [[A]]) 23; ARGPROMOTION-NEXT: call void @ext(<{ [[STRUCT_A]] }>* inalloca [[ARGMEM]]) 24; ARGPROMOTION-NEXT: ret void 25; 26; GLOBALOPT_ARGPROMOTION-LABEL: define {{[^@]+}}@internalfun 27; GLOBALOPT_ARGPROMOTION-SAME: (<{ [[STRUCT_A:%.*]] }>* [[TMP0:%.*]]) unnamed_addr 28; GLOBALOPT_ARGPROMOTION-NEXT: entry: 29; GLOBALOPT_ARGPROMOTION-NEXT: [[A:%.*]] = getelementptr inbounds <{ [[STRUCT_A]] }>, <{ [[STRUCT_A]] }>* [[TMP0]], i32 0, i32 0 30; GLOBALOPT_ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A]] }>, align 4 31; GLOBALOPT_ARGPROMOTION-NEXT: [[TMP1:%.*]] = getelementptr inbounds <{ [[STRUCT_A]] }>, <{ [[STRUCT_A]] }>* [[ARGMEM]], i32 0, i32 0 32; GLOBALOPT_ARGPROMOTION-NEXT: [[CALL:%.*]] = call x86_thiscallcc %struct.a* @copy_ctor(%struct.a* [[TMP1]], %struct.a* dereferenceable(1) [[A]]) 33; GLOBALOPT_ARGPROMOTION-NEXT: call void @ext(<{ [[STRUCT_A]] }>* inalloca [[ARGMEM]]) 34; GLOBALOPT_ARGPROMOTION-NEXT: ret void 35; 36entry: 37 %a = getelementptr inbounds <{ %struct.a }>, <{ %struct.a }>* %0, i32 0, i32 0 38 %argmem = alloca inalloca <{ %struct.a }>, align 4 39 %1 = getelementptr inbounds <{ %struct.a }>, <{ %struct.a }>* %argmem, i32 0, i32 0 40 %call = call x86_thiscallcc %struct.a* @copy_ctor(%struct.a* %1, %struct.a* dereferenceable(1) %a) 41 call void @ext(<{ %struct.a }>* inalloca %argmem) 42 ret void 43} 44 45; This is here to ensure @internalfun is live. 46define void @exportedfun(%struct.a* %a) { 47; ARGPROMOTION-LABEL: define {{[^@]+}}@exportedfun 48; ARGPROMOTION-SAME: (%struct.a* [[A:%.*]]) 49; ARGPROMOTION-NEXT: [[INALLOCA_SAVE:%.*]] = tail call i8* @llvm.stacksave() 50; ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A:%.*]] }>, align 4 51; ARGPROMOTION-NEXT: call x86_thiscallcc void @internalfun(%struct.a* [[A]], <{ [[STRUCT_A]] }>* inalloca [[ARGMEM]]) 52; ARGPROMOTION-NEXT: call void @llvm.stackrestore(i8* [[INALLOCA_SAVE]]) 53; ARGPROMOTION-NEXT: ret void 54; 55; GLOBALOPT_ARGPROMOTION-LABEL: define {{[^@]+}}@exportedfun 56; GLOBALOPT_ARGPROMOTION-SAME: (%struct.a* [[A:%.*]]) local_unnamed_addr 57; GLOBALOPT_ARGPROMOTION-NEXT: [[INALLOCA_SAVE:%.*]] = tail call i8* @llvm.stacksave() 58; GLOBALOPT_ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A:%.*]] }>, align 4 59; GLOBALOPT_ARGPROMOTION-NEXT: call fastcc void @internalfun(<{ [[STRUCT_A]] }>* [[ARGMEM]]) 60; GLOBALOPT_ARGPROMOTION-NEXT: call void @llvm.stackrestore(i8* [[INALLOCA_SAVE]]) 61; GLOBALOPT_ARGPROMOTION-NEXT: ret void 62; 63 %inalloca.save = tail call i8* @llvm.stacksave() 64 %argmem = alloca inalloca <{ %struct.a }>, align 4 65 call x86_thiscallcc void @internalfun(%struct.a* %a, <{ %struct.a }>* inalloca %argmem) 66 call void @llvm.stackrestore(i8* %inalloca.save) 67 ret void 68} 69 70declare x86_thiscallcc %struct.a* @copy_ctor(%struct.a* returned, %struct.a* dereferenceable(1)) 71declare void @ext(<{ %struct.a }>* inalloca) 72declare i8* @llvm.stacksave() 73declare void @llvm.stackrestore(i8*) 74