Home | History | Annotate | Download | only in MergeFunc
      1 ; RUN: opt -O0 -S -mergefunc -mergefunc-preserve-debug-info < %s | FileCheck %s --check-prefix=OPTIMIZATION_LEVEL_0
      2 ; RUN: opt -O2 -S -mergefunc -mergefunc-preserve-debug-info < %s | FileCheck %s --check-prefix=OPTIMIZATION_LEVEL_2
      3 
      4 ; Preserve debug info in thunks under -mergefunc -mergefunc-preserve-debug-info
      5 ;
      6 ; We test that:
      7 ; At -O0 we have preserved the generated @llvm.dbg.declare debug intrinsics.
      8 ; At -O2 we have preserved the generated @llvm.dbg.value debug intrinsics.
      9 ; At -O0, stores from the incoming parameters to locations on the stack-frame
     10 ;         and allocas that create these locations on the stack-frame are preserved.
     11 ; Debug info got generated for the call made by the thunk and for its return value.
     12 ; The foregoing is the only content of a thunk's entry block.
     13 ; A thunk makes a tail call to the shared implementation.
     14 ; A thunk's call site is preserved to point to the thunk (with only -mergefunc the
     15 ;   call site is modified to point to the shared implementation) when both occur
     16 ;   within the same translation unit.
     17 
     18 ; The source code that was used to test and generate this LLVM IR is:
     19 ;
     20 ; int maxA(int x, int y) {
     21 ;   int i, m, j;
     22 ;   if (x > y)
     23 ;     m = x;
     24 ;   else
     25 ;     m = y;
     26 ;   return m;
     27 ; }
     28 ;
     29 ; int maxB(int x, int y) {
     30 ;   int i, m, j;
     31 ;   if (x > y)
     32 ;     m = x;
     33 ;   else
     34 ;     m = y;
     35 ;   return m;
     36 ; }
     37 ;
     38 ; void f(void) {
     39 ;
     40 ;   maxA(3, 4);
     41 ;   maxB(1, 9);
     42 ; }
     43 
     44 ; Function Attrs: nounwind uwtable
     45 define i32 @maxA(i32 %x, i32 %y) !dbg !6 {
     46 entry:
     47   %x.addr = alloca i32, align 4
     48   %y.addr = alloca i32, align 4
     49   %i = alloca i32, align 4
     50   %m = alloca i32, align 4
     51   %j = alloca i32, align 4
     52   store i32 %x, i32* %x.addr, align 4
     53   call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !11, metadata !12), !dbg !13
     54   store i32 %y, i32* %y.addr, align 4
     55   call void @llvm.dbg.declare(metadata i32* %y.addr, metadata !14, metadata !12), !dbg !15
     56   call void @llvm.dbg.declare(metadata i32* %i, metadata !16, metadata !12), !dbg !17
     57   call void @llvm.dbg.declare(metadata i32* %m, metadata !18, metadata !12), !dbg !19
     58   call void @llvm.dbg.declare(metadata i32* %j, metadata !20, metadata !12), !dbg !21
     59   %0 = load i32, i32* %x.addr, align 4, !dbg !22
     60   %1 = load i32, i32* %y.addr, align 4, !dbg !24
     61   %cmp = icmp sgt i32 %0, %1, !dbg !25
     62   br i1 %cmp, label %if.then, label %if.else, !dbg !26
     63 
     64 if.then:                                          ; preds = %entry
     65   %2 = load i32, i32* %x.addr, align 4, !dbg !27
     66   store i32 %2, i32* %m, align 4, !dbg !28
     67   br label %if.end, !dbg !29
     68 
     69 if.else:                                          ; preds = %entry
     70   %3 = load i32, i32* %y.addr, align 4, !dbg !30
     71   store i32 %3, i32* %m, align 4, !dbg !31
     72   br label %if.end
     73 
     74 if.end:                                           ; preds = %if.else, %if.then
     75   %4 = load i32, i32* %m, align 4, !dbg !32
     76   ret i32 %4, !dbg !33
     77 }
     78 
     79 ; Function Attrs: nounwind readnone
     80 declare void @llvm.dbg.declare(metadata, metadata, metadata)
     81 
     82 ; Function Attrs: nounwind uwtable
     83 define i32 @maxB(i32 %x, i32 %y) !dbg !34 {
     84 
     85 ; OPTIMIZATION_LEVEL_0: define i32 @maxB(i32 %x, i32 %y)
     86 ; OPTIMIZATION_LEVEL_0-NEXT: entry:
     87 ; OPTIMIZATION_LEVEL_0-NEXT: %x.addr = alloca i32, align 4
     88 ; OPTIMIZATION_LEVEL_0-NEXT: %y.addr = alloca i32, align 4
     89 ; OPTIMIZATION_LEVEL_0-NEXT: store i32 %x, i32* %x.addr, align 4
     90 ; OPTIMIZATION_LEVEL_0-NEXT: call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !{{[0-9]+}}, metadata !DIExpression()), !dbg !{{[0-9]+}}
     91 ; OPTIMIZATION_LEVEL_0-NEXT: store i32 %y, i32* %y.addr, align 4
     92 ; OPTIMIZATION_LEVEL_0-NEXT: call void @llvm.dbg.declare(metadata i32* %y.addr, metadata !{{[0-9]+}}, metadata !DIExpression()), !dbg !{{[0-9]+}}
     93 ; OPTIMIZATION_LEVEL_0-NEXT: %0 = tail call i32 @maxA(i32 %x, i32 %y), !dbg !{{[0-9]+}}
     94 ; OPTIMIZATION_LEVEL_0-NEXT: ret i32 %0, !dbg !{{[0-9]+}}
     95 ; OPTIMIZATION_LEVEL_0-NEXT: }
     96 
     97 ; OPTIMIZATION_LEVEL_2: define i32 @maxB(i32 %x, i32 %y)
     98 ; OPTIMIZATION_LEVEL_2-NEXT: entry:
     99 ; OPTIMIZATION_LEVEL_2-NEXT: call void @llvm.dbg.value(metadata i32 %x, metadata !{{[0-9]+}}, metadata !DIExpression()), !dbg !{{[0-9]+}}
    100 ; OPTIMIZATION_LEVEL_2-NEXT: call void @llvm.dbg.value(metadata i32 %y, metadata !{{[0-9]+}}, metadata !DIExpression()), !dbg !{{[0-9]+}}
    101 ; OPTIMIZATION_LEVEL_2-NEXT: %0 = tail call i32 @maxA(i32 %x, i32 %y) #{{[0-9]+}}, !dbg !{{[0-9]+}}
    102 ; OPTIMIZATION_LEVEL_2-NEXT: ret i32 %0, !dbg !{{[0-9]+}}
    103 ; OPTIMIZATION_LEVEL_2-NEXT: }
    104 
    105 entry:
    106   %x.addr = alloca i32, align 4
    107   %y.addr = alloca i32, align 4
    108   %i = alloca i32, align 4
    109   %m = alloca i32, align 4
    110   %j = alloca i32, align 4
    111   store i32 %x, i32* %x.addr, align 4
    112   call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !35, metadata !12), !dbg !36
    113   store i32 %y, i32* %y.addr, align 4
    114   call void @llvm.dbg.declare(metadata i32* %y.addr, metadata !37, metadata !12), !dbg !38
    115   call void @llvm.dbg.declare(metadata i32* %i, metadata !39, metadata !12), !dbg !40
    116   call void @llvm.dbg.declare(metadata i32* %m, metadata !41, metadata !12), !dbg !42
    117   call void @llvm.dbg.declare(metadata i32* %j, metadata !43, metadata !12), !dbg !44
    118   %0 = load i32, i32* %x.addr, align 4, !dbg !45
    119   %1 = load i32, i32* %y.addr, align 4, !dbg !47
    120   %cmp = icmp sgt i32 %0, %1, !dbg !48
    121   br i1 %cmp, label %if.then, label %if.else, !dbg !49
    122 
    123 if.then:                                          ; preds = %entry
    124   %2 = load i32, i32* %x.addr, align 4, !dbg !50
    125   store i32 %2, i32* %m, align 4, !dbg !51
    126   br label %if.end, !dbg !52
    127 
    128 if.else:                                          ; preds = %entry
    129   %3 = load i32, i32* %y.addr, align 4, !dbg !53
    130   store i32 %3, i32* %m, align 4, !dbg !54
    131   br label %if.end
    132 
    133 if.end:                                           ; preds = %if.else, %if.then
    134   %4 = load i32, i32* %m, align 4, !dbg !55
    135   ret i32 %4, !dbg !56
    136 }
    137 
    138 ; Function Attrs: nounwind uwtable
    139 define void @f() !dbg !57 {
    140 entry:
    141 
    142 ; OPTIMIZATION_LEVEL_0: define void @f()
    143 ; OPTIMIZATION_LEVEL_0-NEXT: entry:
    144 ; OPTIMIZATION_LEVEL_0-NEXT: %call = call i32 @maxA(i32 3, i32 4), !dbg !{{[0-9]+}}
    145 ; OPTIMIZATION_LEVEL_0-NEXT: %call1 = call i32 @maxB(i32 1, i32 9), !dbg !{{[0-9]+}}
    146 ; OPTIMIZATION_LEVEL_0-NEXT: ret void, !dbg !{{[0-9]+}}
    147 
    148 ; OPTIMIZATION_LEVEL_2: define void @f()
    149 ; OPTIMIZATION_LEVEL_2-NEXT: entry:
    150 ; OPTIMIZATION_LEVEL_2-NEXT: ret void, !dbg !{{[0-9]+}}
    151 
    152   %call = call i32 @maxA(i32 3, i32 4), !dbg !60
    153   %call1 = call i32 @maxB(i32 1, i32 9), !dbg !61
    154   ret void, !dbg !62
    155 }
    156 
    157 !llvm.dbg.cu = !{!0}
    158 !llvm.module.flags = !{!3, !4}
    159 !llvm.ident = !{!5}
    160 
    161 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
    162 !1 = !DIFile(filename: "mergefunc-preserve-debug-info.c", directory: "")
    163 !2 = !{}
    164 !3 = !{i32 2, !"Dwarf Version", i32 4}
    165 !4 = !{i32 2, !"Debug Info Version", i32 3}
    166 !5 = !{!""}
    167 !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)
    168 !7 = !DIFile(filename: "./mergefunc-preserve-debug-info.c", directory: "")
    169 !8 = !DISubroutineType(types: !9)
    170 !9 = !{!10, !10, !10}
    171 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
    172 !11 = !DILocalVariable(name: "x", arg: 1, scope: !6, file: !7, line: 1, type: !10)
    173 !12 = !DIExpression()
    174 !13 = !DILocation(line: 1, column: 14, scope: !6)
    175 !14 = !DILocalVariable(name: "y", arg: 2, scope: !6, file: !7, line: 1, type: !10)
    176 !15 = !DILocation(line: 1, column: 21, scope: !6)
    177 !16 = !DILocalVariable(name: "i", scope: !6, file: !7, line: 2, type: !10)
    178 !17 = !DILocation(line: 2, column: 7, scope: !6)
    179 !18 = !DILocalVariable(name: "m", scope: !6, file: !7, line: 2, type: !10)
    180 !19 = !DILocation(line: 2, column: 10, scope: !6)
    181 !20 = !DILocalVariable(name: "j", scope: !6, file: !7, line: 2, type: !10)
    182 !21 = !DILocation(line: 2, column: 13, scope: !6)
    183 !22 = !DILocation(line: 3, column: 7, scope: !23)
    184 !23 = distinct !DILexicalBlock(scope: !6, file: !7, line: 3, column: 7)
    185 !24 = !DILocation(line: 3, column: 11, scope: !23)
    186 !25 = !DILocation(line: 3, column: 9, scope: !23)
    187 !26 = !DILocation(line: 3, column: 7, scope: !6)
    188 !27 = !DILocation(line: 4, column: 9, scope: !23)
    189 !28 = !DILocation(line: 4, column: 7, scope: !23)
    190 !29 = !DILocation(line: 4, column: 5, scope: !23)
    191 !30 = !DILocation(line: 6, column: 9, scope: !23)
    192 !31 = !DILocation(line: 6, column: 7, scope: !23)
    193 !32 = !DILocation(line: 7, column: 10, scope: !6)
    194 !33 = !DILocation(line: 7, column: 3, scope: !6)
    195 !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)
    196 !35 = !DILocalVariable(name: "x", arg: 1, scope: !34, file: !7, line: 10, type: !10)
    197 !36 = !DILocation(line: 10, column: 14, scope: !34)
    198 !37 = !DILocalVariable(name: "y", arg: 2, scope: !34, file: !7, line: 10, type: !10)
    199 !38 = !DILocation(line: 10, column: 21, scope: !34)
    200 !39 = !DILocalVariable(name: "i", scope: !34, file: !7, line: 11, type: !10)
    201 !40 = !DILocation(line: 11, column: 7, scope: !34)
    202 !41 = !DILocalVariable(name: "m", scope: !34, file: !7, line: 11, type: !10)
    203 !42 = !DILocation(line: 11, column: 10, scope: !34)
    204 !43 = !DILocalVariable(name: "j", scope: !34, file: !7, line: 11, type: !10)
    205 !44 = !DILocation(line: 11, column: 13, scope: !34)
    206 !45 = !DILocation(line: 12, column: 7, scope: !46)
    207 !46 = distinct !DILexicalBlock(scope: !34, file: !7, line: 12, column: 7)
    208 !47 = !DILocation(line: 12, column: 11, scope: !46)
    209 !48 = !DILocation(line: 12, column: 9, scope: !46)
    210 !49 = !DILocation(line: 12, column: 7, scope: !34)
    211 !50 = !DILocation(line: 13, column: 9, scope: !46)
    212 !51 = !DILocation(line: 13, column: 7, scope: !46)
    213 !52 = !DILocation(line: 13, column: 5, scope: !46)
    214 !53 = !DILocation(line: 15, column: 9, scope: !46)
    215 !54 = !DILocation(line: 15, column: 7, scope: !46)
    216 !55 = !DILocation(line: 16, column: 10, scope: !34)
    217 !56 = !DILocation(line: 16, column: 3, scope: !34)
    218 !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)
    219 !58 = !DISubroutineType(types: !59)
    220 !59 = !{null}
    221 !60 = !DILocation(line: 21, column: 3, scope: !57)
    222 !61 = !DILocation(line: 22, column: 3, scope: !57)
    223 !62 = !DILocation(line: 23, column: 1, scope: !57)
    224