1c0cfdd32SJohannes Doerfert; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes 2cee313d2SEric Christopher; RUN: opt < %s -passes=argpromotion -S | FileCheck %s 3cee313d2SEric Christopher 4cee313d2SEric Christopherdeclare void @sink(i32) 5cee313d2SEric Christopher 6*bcbc6151SNikita Popovdefine internal void @test(ptr %X) !dbg !2 { 7c0cfdd32SJohannes Doerfert; CHECK-LABEL: define {{[^@]+}}@test 8a2ce8df4SValery Pykhtin; CHECK-SAME: (i32 [[X_0_VAL_0_VAL:%.*]]) !dbg [[DBG3:![0-9]+]] { 9a2ce8df4SValery Pykhtin; CHECK-NEXT: call void @sink(i32 [[X_0_VAL_0_VAL]]) 10c0cfdd32SJohannes Doerfert; CHECK-NEXT: ret void 11c0cfdd32SJohannes Doerfert; 12*bcbc6151SNikita Popov %1 = load ptr, ptr %X, align 8 13*bcbc6151SNikita Popov %2 = load i32, ptr %1, align 8 14cee313d2SEric Christopher call void @sink(i32 %2) 15cee313d2SEric Christopher ret void 16cee313d2SEric Christopher} 17cee313d2SEric Christopher 18cee313d2SEric Christopher%struct.pair = type { i32, i32 } 19cee313d2SEric Christopher 20170c4d21SPavel Samolysov; Do not promote because there is a store of the pointer %P itself. Even if %P 21170c4d21SPavel Samolysov; had been promoted as a byval argument, the result would have been not 22170c4d21SPavel Samolysov; optimizable for SROA. 23*bcbc6151SNikita Popovdefine internal void @test_byval(ptr byval(%struct.pair) align 4 %P) { 24c0cfdd32SJohannes Doerfert; CHECK-LABEL: define {{[^@]+}}@test_byval 25*bcbc6151SNikita Popov; CHECK-SAME: (ptr byval([[STRUCT_PAIR:%.*]]) align 4 [[P:%.*]]) { 26*bcbc6151SNikita Popov; CHECK-NEXT: [[TMP1:%.*]] = alloca ptr, align 8 27*bcbc6151SNikita Popov; CHECK-NEXT: store ptr [[P]], ptr [[TMP1]], align 8 28c0cfdd32SJohannes Doerfert; CHECK-NEXT: ret void 29c0cfdd32SJohannes Doerfert; 30*bcbc6151SNikita Popov %1 = alloca ptr, align 8 31*bcbc6151SNikita Popov store ptr %P, ptr %1, align 8 ; to protect from promotion 32cee313d2SEric Christopher ret void 33cee313d2SEric Christopher} 34cee313d2SEric Christopher 35*bcbc6151SNikita Popovdefine void @caller(ptr %Y, ptr %P) { 36c0cfdd32SJohannes Doerfert; CHECK-LABEL: define {{[^@]+}}@caller 37*bcbc6151SNikita Popov; CHECK-SAME: (ptr [[Y:%.*]], ptr [[P:%.*]]) { 38*bcbc6151SNikita Popov; CHECK-NEXT: [[Y_VAL:%.*]] = load ptr, ptr [[Y]], align 8, !dbg [[DBG4:![0-9]+]] 39*bcbc6151SNikita Popov; CHECK-NEXT: [[Y_VAL_VAL:%.*]] = load i32, ptr [[Y_VAL]], align 8, !dbg [[DBG4]] 40a2ce8df4SValery Pykhtin; CHECK-NEXT: call void @test(i32 [[Y_VAL_VAL]]), !dbg [[DBG4]] 41*bcbc6151SNikita Popov; CHECK-NEXT: call void @test_byval(ptr byval([[STRUCT_PAIR:%.*]]) align 4 [[P]]), !dbg [[DBG5:![0-9]+]] 42c0cfdd32SJohannes Doerfert; CHECK-NEXT: ret void 43c0cfdd32SJohannes Doerfert; 44*bcbc6151SNikita Popov call void @test(ptr %Y), !dbg !1 45cee313d2SEric Christopher 46*bcbc6151SNikita Popov call void @test_byval(ptr byval(%struct.pair) align 4 %P), !dbg !6 47cee313d2SEric Christopher ret void 48cee313d2SEric Christopher} 49cee313d2SEric Christopher 50cee313d2SEric Christopher 51cee313d2SEric Christopher!llvm.module.flags = !{!0} 52cee313d2SEric Christopher!llvm.dbg.cu = !{!3} 53cee313d2SEric Christopher 54cee313d2SEric Christopher!0 = !{i32 2, !"Debug Info Version", i32 3} 55cee313d2SEric Christopher!1 = !DILocation(line: 8, scope: !2) 56cee313d2SEric Christopher!2 = distinct !DISubprogram(name: "test", file: !5, line: 3, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !3, scopeLine: 3, scope: null) 57cee313d2SEric Christopher!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: LineTablesOnly, file: !5) 58cee313d2SEric Christopher!5 = !DIFile(filename: "test.c", directory: "") 59cee313d2SEric Christopher!6 = !DILocation(line: 9, scope: !2) 60