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 -passes=argpromotion %s | FileCheck %s --check-prefix=ARGPROMOTION 8; RUN: opt -S -passes=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(ptr %this, ptr inalloca(<{ %struct.a }>)) { 16; ARGPROMOTION-LABEL: define {{[^@]+}}@internalfun 17; ARGPROMOTION-SAME: (ptr [[THIS:%.*]], ptr inalloca(<{ [[STRUCT_A:%.*]] }>) [[TMP0:%.*]]) { 18; ARGPROMOTION-NEXT: entry: 19; ARGPROMOTION-NEXT: [[A:%.*]] = getelementptr inbounds <{ [[STRUCT_A]] }>, ptr [[TMP0]], i32 0, i32 0 20; ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A]] }>, align 4 21; ARGPROMOTION-NEXT: [[TMP1:%.*]] = getelementptr inbounds <{ [[STRUCT_A]] }>, ptr [[ARGMEM]], i32 0, i32 0 22; ARGPROMOTION-NEXT: [[CALL:%.*]] = call x86_thiscallcc ptr @copy_ctor(ptr [[TMP1]], ptr dereferenceable(1) [[A]]) 23; ARGPROMOTION-NEXT: call void @ext(ptr inalloca(<{ [[STRUCT_A]] }>) [[ARGMEM]]) 24; ARGPROMOTION-NEXT: ret void 25; 26; GLOBALOPT_ARGPROMOTION-LABEL: define {{[^@]+}}@internalfun 27; GLOBALOPT_ARGPROMOTION-SAME: (ptr [[TMP0:%.*]]) unnamed_addr { 28; GLOBALOPT_ARGPROMOTION-NEXT: entry: 29; GLOBALOPT_ARGPROMOTION-NEXT: [[A:%.*]] = getelementptr inbounds <{ [[STRUCT_A:%.*]] }>, ptr [[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]] }>, ptr [[ARGMEM]], i32 0, i32 0 32; GLOBALOPT_ARGPROMOTION-NEXT: [[CALL:%.*]] = call x86_thiscallcc ptr @copy_ctor(ptr [[TMP1]], ptr dereferenceable(1) [[A]]) 33; GLOBALOPT_ARGPROMOTION-NEXT: call void @ext(ptr inalloca(<{ [[STRUCT_A]] }>) [[ARGMEM]]) 34; GLOBALOPT_ARGPROMOTION-NEXT: ret void 35; 36entry: 37 %a = getelementptr inbounds <{ %struct.a }>, ptr %0, i32 0, i32 0 38 %argmem = alloca inalloca <{ %struct.a }>, align 4 39 %1 = getelementptr inbounds <{ %struct.a }>, ptr %argmem, i32 0, i32 0 40 %call = call x86_thiscallcc ptr @copy_ctor(ptr %1, ptr dereferenceable(1) %a) 41 call void @ext(ptr inalloca(<{ %struct.a }>) %argmem) 42 ret void 43} 44 45; This is here to ensure @internalfun is live. 46define void @exportedfun(ptr %a) { 47; ARGPROMOTION-LABEL: define {{[^@]+}}@exportedfun 48; ARGPROMOTION-SAME: (ptr [[A:%.*]]) { 49; ARGPROMOTION-NEXT: [[INALLOCA_SAVE:%.*]] = tail call ptr @llvm.stacksave.p0() 50; ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A:%.*]] }>, align 4 51; ARGPROMOTION-NEXT: call x86_thiscallcc void @internalfun(ptr [[A]], ptr inalloca(<{ [[STRUCT_A]] }>) [[ARGMEM]]) 52; ARGPROMOTION-NEXT: call void @llvm.stackrestore.p0(ptr [[INALLOCA_SAVE]]) 53; ARGPROMOTION-NEXT: ret void 54; 55; GLOBALOPT_ARGPROMOTION-LABEL: define {{[^@]+}}@exportedfun 56; GLOBALOPT_ARGPROMOTION-SAME: (ptr [[A:%.*]]) local_unnamed_addr { 57; GLOBALOPT_ARGPROMOTION-NEXT: [[INALLOCA_SAVE:%.*]] = tail call ptr @llvm.stacksave.p0() 58; GLOBALOPT_ARGPROMOTION-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_A:%.*]] }>, align 4 59; GLOBALOPT_ARGPROMOTION-NEXT: call fastcc void @internalfun(ptr [[ARGMEM]]) 60; GLOBALOPT_ARGPROMOTION-NEXT: call void @llvm.stackrestore.p0(ptr [[INALLOCA_SAVE]]) 61; GLOBALOPT_ARGPROMOTION-NEXT: ret void 62; 63 %inalloca.save = tail call ptr @llvm.stacksave() 64 %argmem = alloca inalloca <{ %struct.a }>, align 4 65 call x86_thiscallcc void @internalfun(ptr %a, ptr inalloca(<{ %struct.a }>) %argmem) 66 call void @llvm.stackrestore(ptr %inalloca.save) 67 ret void 68} 69 70declare x86_thiscallcc ptr @copy_ctor(ptr returned, ptr dereferenceable(1)) 71declare void @ext(ptr inalloca(<{ %struct.a }>)) 72declare ptr @llvm.stacksave() 73declare void @llvm.stackrestore(ptr) 74