269 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 22; RUN: opt -passes='default<O0>,mergefunc' -S -mergefunc-preserve-debug-info < %s | FileCheck %s --check-prefix=OPTIMIZATION_LEVEL_03; RUN: opt -passes='default<O2>,mergefunc' -S -mergefunc-preserve-debug-info < %s | FileCheck %s --check-prefix=OPTIMIZATION_LEVEL_24 5; Preserve debug info in thunks under -passes=mergefunc -mergefunc-preserve-debug-info6;7; We test that:8; At -O0 we have preserved the generated @llvm.dbg.declare debug intrinsics.9; At -O2 we have preserved the generated @llvm.dbg.value debug intrinsics.10; At -O0, stores from the incoming parameters to locations on the stack-frame11; and allocas that create these locations on the stack-frame are preserved.12; Debug info got generated for the call made by the thunk and for its return value.13; The foregoing is the only content of a thunk's entry block.14; A thunk makes a tail call to the shared implementation.15; A thunk's call site is preserved to point to the thunk (with only -passes=mergefunc the16; call site is modified to point to the shared implementation) when both occur17; within the same translation unit.18 19; The source code that was used to test and generate this LLVM IR is:20;21; int maxA(int x, int y) {22; int i, m, j;23; if (x > y)24; m = x;25; else26; m = y;27; return m;28; }29;30; int maxB(int x, int y) {31; int i, m, j;32; if (x > y)33; m = x;34; else35; m = y;36; return m;37; }38;39; void f(void) {40;41; maxA(3, 4);42; maxB(1, 9);43; }44 45; Function Attrs: nounwind uwtable46define i32 @maxA(i32 %x, i32 %y) !dbg !6 {47; OPTIMIZATION_LEVEL_0-LABEL: define i32 @maxA48; OPTIMIZATION_LEVEL_0-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]]) !dbg [[DBG6:![0-9]+]] {49; OPTIMIZATION_LEVEL_0-NEXT: entry:50; OPTIMIZATION_LEVEL_0-NEXT: [[X_ADDR:%.*]] = alloca i32, align 451; OPTIMIZATION_LEVEL_0-NEXT: [[Y_ADDR:%.*]] = alloca i32, align 452; OPTIMIZATION_LEVEL_0-NEXT: [[I:%.*]] = alloca i32, align 453; OPTIMIZATION_LEVEL_0-NEXT: [[M:%.*]] = alloca i32, align 454; OPTIMIZATION_LEVEL_0-NEXT: [[J:%.*]] = alloca i32, align 455; OPTIMIZATION_LEVEL_0-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 456; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[X_ADDR]], [[META11:![0-9]+]], !DIExpression(), [[META12:![0-9]+]])57; OPTIMIZATION_LEVEL_0-NEXT: store i32 [[Y]], ptr [[Y_ADDR]], align 458; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[Y_ADDR]], [[META13:![0-9]+]], !DIExpression(), [[META14:![0-9]+]])59; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[I]], [[META15:![0-9]+]], !DIExpression(), [[META16:![0-9]+]])60; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[M]], [[META17:![0-9]+]], !DIExpression(), [[META18:![0-9]+]])61; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[J]], [[META19:![0-9]+]], !DIExpression(), [[META20:![0-9]+]])62; OPTIMIZATION_LEVEL_0-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4, !dbg [[DBG21:![0-9]+]]63; OPTIMIZATION_LEVEL_0-NEXT: [[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4, !dbg [[DBG23:![0-9]+]]64; OPTIMIZATION_LEVEL_0-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP0]], [[TMP1]], !dbg [[DBG24:![0-9]+]]65; OPTIMIZATION_LEVEL_0-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]], !dbg [[DBG25:![0-9]+]]66; OPTIMIZATION_LEVEL_0: if.then:67; OPTIMIZATION_LEVEL_0-NEXT: [[TMP2:%.*]] = load i32, ptr [[X_ADDR]], align 4, !dbg [[DBG26:![0-9]+]]68; OPTIMIZATION_LEVEL_0-NEXT: store i32 [[TMP2]], ptr [[M]], align 4, !dbg [[DBG27:![0-9]+]]69; OPTIMIZATION_LEVEL_0-NEXT: br label [[IF_END:%.*]], !dbg [[DBG28:![0-9]+]]70; OPTIMIZATION_LEVEL_0: if.else:71; OPTIMIZATION_LEVEL_0-NEXT: [[TMP3:%.*]] = load i32, ptr [[Y_ADDR]], align 4, !dbg [[DBG29:![0-9]+]]72; OPTIMIZATION_LEVEL_0-NEXT: store i32 [[TMP3]], ptr [[M]], align 4, !dbg [[DBG30:![0-9]+]]73; OPTIMIZATION_LEVEL_0-NEXT: br label [[IF_END]]74; OPTIMIZATION_LEVEL_0: if.end:75; OPTIMIZATION_LEVEL_0-NEXT: [[TMP4:%.*]] = load i32, ptr [[M]], align 4, !dbg [[DBG31:![0-9]+]]76; OPTIMIZATION_LEVEL_0-NEXT: ret i32 [[TMP4]], !dbg [[DBG32:![0-9]+]]77;78; OPTIMIZATION_LEVEL_2-LABEL: define i32 @maxA79; OPTIMIZATION_LEVEL_2-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !dbg [[DBG6:![0-9]+]] {80; OPTIMIZATION_LEVEL_2-NEXT: entry:81; OPTIMIZATION_LEVEL_2-NEXT: #dbg_value(i32 [[X]], [[META11:![0-9]+]], !DIExpression(), [[META12:![0-9]+]])82; OPTIMIZATION_LEVEL_2-NEXT: #dbg_value(i32 [[Y]], [[META13:![0-9]+]], !DIExpression(), [[META12]])83; OPTIMIZATION_LEVEL_2-NEXT: #dbg_declare(ptr poison, [[META14:![0-9]+]], !DIExpression(), [[META15:![0-9]+]])84; OPTIMIZATION_LEVEL_2-NEXT: #dbg_declare(ptr poison, [[META16:![0-9]+]], !DIExpression(), [[META17:![0-9]+]])85; OPTIMIZATION_LEVEL_2-NEXT: [[X_Y:%.*]] = tail call i32 @llvm.smax.i32(i32 [[X]], i32 [[Y]])86; OPTIMIZATION_LEVEL_2-NEXT: #dbg_value(i32 [[X_Y]], [[META18:![0-9]+]], !DIExpression(), [[META12]])87; OPTIMIZATION_LEVEL_2-NEXT: ret i32 [[X_Y]], !dbg [[DBG19:![0-9]+]]88;89entry:90 %x.addr = alloca i32, align 491 %y.addr = alloca i32, align 492 %i = alloca i32, align 493 %m = alloca i32, align 494 %j = alloca i32, align 495 store i32 %x, ptr %x.addr, align 496 call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !11, metadata !12), !dbg !1397 store i32 %y, ptr %y.addr, align 498 call void @llvm.dbg.declare(metadata ptr %y.addr, metadata !14, metadata !12), !dbg !1599 call void @llvm.dbg.declare(metadata ptr %i, metadata !16, metadata !12), !dbg !17100 call void @llvm.dbg.declare(metadata ptr %m, metadata !18, metadata !12), !dbg !19101 call void @llvm.dbg.declare(metadata ptr %j, metadata !20, metadata !12), !dbg !21102 %0 = load i32, ptr %x.addr, align 4, !dbg !22103 %1 = load i32, ptr %y.addr, align 4, !dbg !24104 %cmp = icmp sgt i32 %0, %1, !dbg !25105 br i1 %cmp, label %if.then, label %if.else, !dbg !26106 107if.then: ; preds = %entry108 %2 = load i32, ptr %x.addr, align 4, !dbg !27109 store i32 %2, ptr %m, align 4, !dbg !28110 br label %if.end, !dbg !29111 112if.else: ; preds = %entry113 %3 = load i32, ptr %y.addr, align 4, !dbg !30114 store i32 %3, ptr %m, align 4, !dbg !31115 br label %if.end116 117if.end: ; preds = %if.else, %if.then118 %4 = load i32, ptr %m, align 4, !dbg !32119 ret i32 %4, !dbg !33120}121 122; Function Attrs: nounwind readnone123declare void @llvm.dbg.declare(metadata, metadata, metadata)124 125; Function Attrs: nounwind uwtable126define i32 @maxB(i32 %x, i32 %y) !dbg !34 {127; OPTIMIZATION_LEVEL_0-LABEL: define i32 @maxB128; OPTIMIZATION_LEVEL_0-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]]) !dbg [[DBG33:![0-9]+]] {129; OPTIMIZATION_LEVEL_0-NEXT: entry:130; OPTIMIZATION_LEVEL_0-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4131; OPTIMIZATION_LEVEL_0-NEXT: [[Y_ADDR:%.*]] = alloca i32, align 4132; OPTIMIZATION_LEVEL_0-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4133; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[X_ADDR]], [[META34:![0-9]+]], !DIExpression(), [[META35:![0-9]+]])134; OPTIMIZATION_LEVEL_0-NEXT: store i32 [[Y]], ptr [[Y_ADDR]], align 4135; OPTIMIZATION_LEVEL_0-NEXT: #dbg_declare(ptr [[Y_ADDR]], [[META36:![0-9]+]], !DIExpression(), [[META37:![0-9]+]])136; OPTIMIZATION_LEVEL_0-NEXT: [[TMP0:%.*]] = tail call i32 @maxA(i32 [[X]], i32 [[Y]]), !dbg [[DBG38:![0-9]+]]137; OPTIMIZATION_LEVEL_0-NEXT: ret i32 [[TMP0]], !dbg [[DBG38]]138;139; OPTIMIZATION_LEVEL_2-LABEL: define i32 @maxB140; OPTIMIZATION_LEVEL_2-SAME: (i32 [[X:%.*]], i32 [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] !dbg [[DBG20:![0-9]+]] {141; OPTIMIZATION_LEVEL_2-NEXT: entry:142; OPTIMIZATION_LEVEL_2-NEXT: #dbg_value(i32 [[X]], [[META21:![0-9]+]], !DIExpression(), [[META22:![0-9]+]])143; OPTIMIZATION_LEVEL_2-NEXT: #dbg_value(i32 [[Y]], [[META23:![0-9]+]], !DIExpression(), [[META22]])144; OPTIMIZATION_LEVEL_2-NEXT: [[TMP0:%.*]] = tail call i32 @maxA(i32 [[X]], i32 [[Y]]) #[[ATTR0]], !dbg [[DBG24:![0-9]+]]145; OPTIMIZATION_LEVEL_2-NEXT: ret i32 [[TMP0]], !dbg [[DBG24]]146;147 148 149entry:150 %x.addr = alloca i32, align 4151 %y.addr = alloca i32, align 4152 %i = alloca i32, align 4153 %m = alloca i32, align 4154 %j = alloca i32, align 4155 store i32 %x, ptr %x.addr, align 4156 call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !35, metadata !12), !dbg !36157 store i32 %y, ptr %y.addr, align 4158 call void @llvm.dbg.declare(metadata ptr %y.addr, metadata !37, metadata !12), !dbg !38159 call void @llvm.dbg.declare(metadata ptr %i, metadata !39, metadata !12), !dbg !40160 call void @llvm.dbg.declare(metadata ptr %m, metadata !41, metadata !12), !dbg !42161 call void @llvm.dbg.declare(metadata ptr %j, metadata !43, metadata !12), !dbg !44162 %0 = load i32, ptr %x.addr, align 4, !dbg !45163 %1 = load i32, ptr %y.addr, align 4, !dbg !47164 %cmp = icmp sgt i32 %0, %1, !dbg !48165 br i1 %cmp, label %if.then, label %if.else, !dbg !49166 167if.then: ; preds = %entry168 %2 = load i32, ptr %x.addr, align 4, !dbg !50169 store i32 %2, ptr %m, align 4, !dbg !51170 br label %if.end, !dbg !52171 172if.else: ; preds = %entry173 %3 = load i32, ptr %y.addr, align 4, !dbg !53174 store i32 %3, ptr %m, align 4, !dbg !54175 br label %if.end176 177if.end: ; preds = %if.else, %if.then178 %4 = load i32, ptr %m, align 4, !dbg !55179 ret i32 %4, !dbg !56180}181 182; Function Attrs: nounwind uwtable183define void @f() !dbg !57 {184; OPTIMIZATION_LEVEL_0-LABEL: define void @f185; OPTIMIZATION_LEVEL_0-SAME: () !dbg [[DBG39:![0-9]+]] {186; OPTIMIZATION_LEVEL_0-NEXT: entry:187; OPTIMIZATION_LEVEL_0-NEXT: [[CALL:%.*]] = call i32 @maxA(i32 3, i32 4), !dbg [[DBG42:![0-9]+]]188; OPTIMIZATION_LEVEL_0-NEXT: [[CALL1:%.*]] = call i32 @maxB(i32 1, i32 9), !dbg [[DBG43:![0-9]+]]189; OPTIMIZATION_LEVEL_0-NEXT: ret void, !dbg [[DBG44:![0-9]+]]190;191; OPTIMIZATION_LEVEL_2-LABEL: define void @f192; OPTIMIZATION_LEVEL_2-SAME: () local_unnamed_addr #[[ATTR0]] !dbg [[DBG25:![0-9]+]] {193; OPTIMIZATION_LEVEL_2-NEXT: entry:194; OPTIMIZATION_LEVEL_2-NEXT: ret void, !dbg [[DBG28:![0-9]+]]195;196entry:197 %call = call i32 @maxA(i32 3, i32 4), !dbg !60198 %call1 = call i32 @maxB(i32 1, i32 9), !dbg !61199 ret void, !dbg !62200}201 202!llvm.dbg.cu = !{!0}203!llvm.module.flags = !{!3, !4}204!llvm.ident = !{!5}205 206!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)207!1 = !DIFile(filename: "mergefunc-preserve-debug-info.c", directory: "")208!2 = !{}209!3 = !{i32 2, !"Dwarf Version", i32 4}210!4 = !{i32 2, !"Debug Info Version", i32 3}211!5 = !{!""}212!6 = distinct !DISubprogram(name: "maxA", scope: !7, file: !7, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)213!7 = !DIFile(filename: "./mergefunc-preserve-debug-info.c", directory: "")214!8 = !DISubroutineType(types: !9)215!9 = !{!10, !10, !10}216!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)217!11 = !DILocalVariable(name: "x", arg: 1, scope: !6, file: !7, line: 1, type: !10)218!12 = !DIExpression()219!13 = !DILocation(line: 1, column: 14, scope: !6)220!14 = !DILocalVariable(name: "y", arg: 2, scope: !6, file: !7, line: 1, type: !10)221!15 = !DILocation(line: 1, column: 21, scope: !6)222!16 = !DILocalVariable(name: "i", scope: !6, file: !7, line: 2, type: !10)223!17 = !DILocation(line: 2, column: 7, scope: !6)224!18 = !DILocalVariable(name: "m", scope: !6, file: !7, line: 2, type: !10)225!19 = !DILocation(line: 2, column: 10, scope: !6)226!20 = !DILocalVariable(name: "j", scope: !6, file: !7, line: 2, type: !10)227!21 = !DILocation(line: 2, column: 13, scope: !6)228!22 = !DILocation(line: 3, column: 7, scope: !23)229!23 = distinct !DILexicalBlock(scope: !6, file: !7, line: 3, column: 7)230!24 = !DILocation(line: 3, column: 11, scope: !23)231!25 = !DILocation(line: 3, column: 9, scope: !23)232!26 = !DILocation(line: 3, column: 7, scope: !6)233!27 = !DILocation(line: 4, column: 9, scope: !23)234!28 = !DILocation(line: 4, column: 7, scope: !23)235!29 = !DILocation(line: 4, column: 5, scope: !23)236!30 = !DILocation(line: 6, column: 9, scope: !23)237!31 = !DILocation(line: 6, column: 7, scope: !23)238!32 = !DILocation(line: 7, column: 10, scope: !6)239!33 = !DILocation(line: 7, column: 3, scope: !6)240!34 = distinct !DISubprogram(name: "maxB", scope: !7, file: !7, line: 10, type: !8, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)241!35 = !DILocalVariable(name: "x", arg: 1, scope: !34, file: !7, line: 10, type: !10)242!36 = !DILocation(line: 10, column: 14, scope: !34)243!37 = !DILocalVariable(name: "y", arg: 2, scope: !34, file: !7, line: 10, type: !10)244!38 = !DILocation(line: 10, column: 21, scope: !34)245!39 = !DILocalVariable(name: "i", scope: !34, file: !7, line: 11, type: !10)246!40 = !DILocation(line: 11, column: 7, scope: !34)247!41 = !DILocalVariable(name: "m", scope: !34, file: !7, line: 11, type: !10)248!42 = !DILocation(line: 11, column: 10, scope: !34)249!43 = !DILocalVariable(name: "j", scope: !34, file: !7, line: 11, type: !10)250!44 = !DILocation(line: 11, column: 13, scope: !34)251!45 = !DILocation(line: 12, column: 7, scope: !46)252!46 = distinct !DILexicalBlock(scope: !34, file: !7, line: 12, column: 7)253!47 = !DILocation(line: 12, column: 11, scope: !46)254!48 = !DILocation(line: 12, column: 9, scope: !46)255!49 = !DILocation(line: 12, column: 7, scope: !34)256!50 = !DILocation(line: 13, column: 9, scope: !46)257!51 = !DILocation(line: 13, column: 7, scope: !46)258!52 = !DILocation(line: 13, column: 5, scope: !46)259!53 = !DILocation(line: 15, column: 9, scope: !46)260!54 = !DILocation(line: 15, column: 7, scope: !46)261!55 = !DILocation(line: 16, column: 10, scope: !34)262!56 = !DILocation(line: 16, column: 3, scope: !34)263!57 = distinct !DISubprogram(name: "f", scope: !7, file: !7, line: 19, type: !58, isLocal: false, isDefinition: true, scopeLine: 19, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)264!58 = !DISubroutineType(types: !59)265!59 = !{null}266!60 = !DILocation(line: 21, column: 3, scope: !57)267!61 = !DILocation(line: 22, column: 3, scope: !57)268!62 = !DILocation(line: 23, column: 1, scope: !57)269