Reid Kleckner | 0828699 | 2018-04-11 16:03:07 +0000 | [diff] [blame] | 1 | ; RUN: llc -fast-isel-sink-local-values -O0 < %s | FileCheck %s |
Reid Kleckner | 3a7a2e4 | 2018-03-14 21:54:21 +0000 | [diff] [blame] | 2 | |
| 3 | target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" |
| 4 | target triple = "i386-linux-gnu" |
| 5 | |
| 6 | ; Try some simple cases that show how local value sinking improves line tables. |
| 7 | |
| 8 | @sink_across = external global i32 |
| 9 | |
| 10 | declare void @simple_callee(i32, i32) |
| 11 | |
| 12 | define void @simple() !dbg !5 { |
| 13 | store i32 44, i32* @sink_across, !dbg !7 |
| 14 | call void @simple_callee(i32 13, i32 55), !dbg !8 |
| 15 | ret void, !dbg !9 |
| 16 | } |
| 17 | |
| 18 | ; CHECK-LABEL: simple: |
| 19 | ; CHECK-NOT: movl $13, |
| 20 | ; CHECK: .loc 1 1 1 prologue_end |
| 21 | ; CHECK: movl $44, sink_across |
| 22 | ; CHECK: .loc 1 2 1 |
| 23 | ; CHECK: movl $13, |
| 24 | ; CHECK: movl $55, |
| 25 | ; CHECK: calll simple_callee |
| 26 | |
| 27 | declare void @simple_reg_callee(i32 inreg, i32 inreg) |
| 28 | |
| 29 | define void @simple_reg() !dbg !10 { |
| 30 | store i32 44, i32* @sink_across, !dbg !11 |
| 31 | call void @simple_reg_callee(i32 inreg 13, i32 inreg 55), !dbg !12 |
| 32 | ret void, !dbg !13 |
| 33 | } |
| 34 | |
| 35 | ; CHECK-LABEL: simple_reg: |
| 36 | ; CHECK: .loc 1 4 1 prologue_end |
| 37 | ; CHECK: movl $44, sink_across |
| 38 | ; CHECK: .loc 1 5 1 |
| 39 | ; CHECK: movl $13, |
| 40 | ; CHECK: movl $55, |
| 41 | ; CHECK: calll simple_reg_callee |
| 42 | |
| 43 | ; There are two interesting cases where local values have no uses but are not |
| 44 | ; dead: when the local value is directly used by a phi, and when the local |
| 45 | ; value is used by a no-op cast instruction. In these cases, we get side tables |
| 46 | ; referring to the local value vreg that we need to check. |
| 47 | |
| 48 | define i8* @phi_const(i32 %c) !dbg !14 { |
| 49 | entry: |
| 50 | %tobool = icmp eq i32 %c, 0, !dbg !20 |
| 51 | call void @llvm.dbg.value(metadata i1 %tobool, metadata !16, metadata !DIExpression()), !dbg !20 |
| 52 | br i1 %tobool, label %if.else, label %if.then, !dbg !21 |
| 53 | |
| 54 | if.then: ; preds = %entry |
| 55 | br label %if.end, !dbg !22 |
| 56 | |
| 57 | if.else: ; preds = %entry |
| 58 | br label %if.end, !dbg !23 |
| 59 | |
| 60 | if.end: ; preds = %if.else, %if.then |
| 61 | %r.0 = phi i8* [ inttoptr (i32 42 to i8*), %if.then ], [ inttoptr (i32 1 to i8*), %if.else ], !dbg !24 |
| 62 | call void @llvm.dbg.value(metadata i8* %r.0, metadata !18, metadata !DIExpression()), !dbg !24 |
| 63 | ret i8* %r.0, !dbg !25 |
| 64 | } |
| 65 | |
| 66 | ; CHECK-LABEL: phi_const: |
| 67 | ; CHECK: # %entry |
| 68 | ; CHECK: cmpl $0, |
| 69 | ; CHECK: # %if.then |
| 70 | ; CHECK: movl $42, |
| 71 | ; CHECK: jmp |
| 72 | ; CHECK: # %if.else |
| 73 | ; CHECK: movl $1, |
| 74 | ; CHECK: # %if.end |
| 75 | |
| 76 | define i8* @phi_const_cast(i32 %c) !dbg !26 { |
| 77 | entry: |
| 78 | %tobool = icmp eq i32 %c, 0, !dbg !32 |
| 79 | call void @llvm.dbg.value(metadata i1 %tobool, metadata !28, metadata !DIExpression()), !dbg !32 |
| 80 | br i1 %tobool, label %if.else, label %if.then, !dbg !33 |
| 81 | |
| 82 | if.then: ; preds = %entry |
| 83 | %v42 = inttoptr i32 42 to i8*, !dbg !34 |
| 84 | call void @llvm.dbg.value(metadata i8* %v42, metadata !29, metadata !DIExpression()), !dbg !34 |
| 85 | br label %if.end, !dbg !35 |
| 86 | |
| 87 | if.else: ; preds = %entry |
| 88 | %v1 = inttoptr i32 1 to i8*, !dbg !36 |
| 89 | call void @llvm.dbg.value(metadata i8* %v1, metadata !30, metadata !DIExpression()), !dbg !36 |
| 90 | br label %if.end, !dbg !37 |
| 91 | |
| 92 | if.end: ; preds = %if.else, %if.then |
| 93 | %r.0 = phi i8* [ %v42, %if.then ], [ %v1, %if.else ], !dbg !38 |
| 94 | call void @llvm.dbg.value(metadata i8* %r.0, metadata !31, metadata !DIExpression()), !dbg !38 |
| 95 | ret i8* %r.0, !dbg !39 |
| 96 | } |
| 97 | |
| 98 | ; CHECK-LABEL: phi_const_cast: |
| 99 | ; CHECK: # %entry |
| 100 | ; CHECK: cmpl $0, |
| 101 | ; CHECK: # %if.then |
| 102 | ; CHECK: movl $42, %[[REG:[a-z]+]] |
| 103 | ; CHECK: #DEBUG_VALUE: phi_const_cast:4 <- $[[REG]] |
| 104 | ; CHECK: jmp |
| 105 | ; CHECK: # %if.else |
| 106 | ; CHECK: movl $1, %[[REG:[a-z]+]] |
| 107 | ; CHECK: #DEBUG_VALUE: phi_const_cast:5 <- $[[REG]] |
| 108 | ; CHECK: # %if.end |
| 109 | |
| 110 | declare void @may_throw() local_unnamed_addr #1 |
| 111 | |
| 112 | declare i32 @__gxx_personality_v0(...) |
| 113 | |
| 114 | define i32 @invoke_phi() personality i32 (...)* @__gxx_personality_v0 { |
| 115 | entry: |
| 116 | store i32 42, i32* @sink_across |
| 117 | invoke void @may_throw() |
| 118 | to label %try.cont unwind label %lpad |
| 119 | |
| 120 | lpad: ; preds = %entry |
| 121 | %0 = landingpad { i8*, i32 } |
| 122 | catch i8* null |
| 123 | store i32 42, i32* @sink_across |
| 124 | br label %try.cont |
| 125 | |
| 126 | try.cont: ; preds = %entry, %lpad |
| 127 | %r.0 = phi i32 [ 13, %entry ], [ 55, %lpad ] |
| 128 | ret i32 %r.0 |
| 129 | } |
| 130 | |
| 131 | ; The constant materialization should be *after* the stores to sink_across, but |
| 132 | ; before any EH_LABEL. |
| 133 | |
| 134 | ; CHECK-LABEL: invoke_phi: |
| 135 | ; CHECK: movl $42, sink_across |
| 136 | ; CHECK: movl $13, %{{[a-z]*}} |
| 137 | ; CHECK: .Ltmp{{.*}}: |
| 138 | ; CHECK: calll may_throw |
| 139 | ; CHECK: .Ltmp{{.*}}: |
| 140 | ; CHECK: jmp .LBB{{.*}} |
| 141 | ; CHECK: .LBB{{.*}}: # %lpad |
| 142 | ; CHECK: movl $42, sink_across |
| 143 | ; CHECK: movl $55, %{{[a-z]*}} |
| 144 | ; CHECK: .LBB{{.*}}: # %try.cont |
| 145 | ; CHECK: retl |
| 146 | |
| 147 | |
| 148 | ; Function Attrs: nounwind readnone speculatable |
| 149 | declare void @llvm.dbg.value(metadata, metadata, metadata) #0 |
| 150 | |
| 151 | attributes #0 = { nounwind readnone speculatable } |
| 152 | |
| 153 | !llvm.dbg.cu = !{!0} |
| 154 | !llvm.debugify = !{!3, !4} |
| 155 | !llvm.module.flags = !{!52, !53} |
| 156 | |
| 157 | !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) |
| 158 | !1 = !DIFile(filename: "../llvm/test/CodeGen/X86/sink-local-value.ll", directory: "/") |
| 159 | !2 = !{} |
| 160 | !3 = !{i32 27} |
| 161 | !4 = !{i32 8} |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 162 | !5 = distinct !DISubprogram(name: "simple", linkageName: "simple", scope: null, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !2) |
Reid Kleckner | 3a7a2e4 | 2018-03-14 21:54:21 +0000 | [diff] [blame] | 163 | !6 = !DISubroutineType(types: !2) |
| 164 | !7 = !DILocation(line: 1, column: 1, scope: !5) |
| 165 | !8 = !DILocation(line: 2, column: 1, scope: !5) |
| 166 | !9 = !DILocation(line: 3, column: 1, scope: !5) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 167 | !10 = distinct !DISubprogram(name: "simple_reg", linkageName: "simple_reg", scope: null, file: !1, line: 4, type: !6, isLocal: false, isDefinition: true, scopeLine: 4, isOptimized: true, unit: !0, retainedNodes: !2) |
Reid Kleckner | 3a7a2e4 | 2018-03-14 21:54:21 +0000 | [diff] [blame] | 168 | !11 = !DILocation(line: 4, column: 1, scope: !10) |
| 169 | !12 = !DILocation(line: 5, column: 1, scope: !10) |
| 170 | !13 = !DILocation(line: 6, column: 1, scope: !10) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 171 | !14 = distinct !DISubprogram(name: "phi_const", linkageName: "phi_const", scope: null, file: !1, line: 7, type: !6, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !0, retainedNodes: !15) |
Reid Kleckner | 3a7a2e4 | 2018-03-14 21:54:21 +0000 | [diff] [blame] | 172 | !15 = !{!16, !18} |
| 173 | !16 = !DILocalVariable(name: "1", scope: !14, file: !1, line: 7, type: !17) |
| 174 | !17 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned) |
| 175 | !18 = !DILocalVariable(name: "2", scope: !14, file: !1, line: 11, type: !19) |
| 176 | !19 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned) |
| 177 | !20 = !DILocation(line: 7, column: 1, scope: !14) |
| 178 | !21 = !DILocation(line: 8, column: 1, scope: !14) |
| 179 | !22 = !DILocation(line: 9, column: 1, scope: !14) |
| 180 | !23 = !DILocation(line: 10, column: 1, scope: !14) |
| 181 | !24 = !DILocation(line: 11, column: 1, scope: !14) |
| 182 | !25 = !DILocation(line: 12, column: 1, scope: !14) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 183 | !26 = distinct !DISubprogram(name: "phi_const_cast", linkageName: "phi_const_cast", scope: null, file: !1, line: 13, type: !6, isLocal: false, isDefinition: true, scopeLine: 13, isOptimized: true, unit: !0, retainedNodes: !27) |
Reid Kleckner | 3a7a2e4 | 2018-03-14 21:54:21 +0000 | [diff] [blame] | 184 | !27 = !{!28, !29, !30, !31} |
| 185 | !28 = !DILocalVariable(name: "3", scope: !26, file: !1, line: 13, type: !17) |
| 186 | !29 = !DILocalVariable(name: "4", scope: !26, file: !1, line: 15, type: !19) |
| 187 | !30 = !DILocalVariable(name: "5", scope: !26, file: !1, line: 17, type: !19) |
| 188 | !31 = !DILocalVariable(name: "6", scope: !26, file: !1, line: 19, type: !19) |
| 189 | !32 = !DILocation(line: 13, column: 1, scope: !26) |
| 190 | !33 = !DILocation(line: 14, column: 1, scope: !26) |
| 191 | !34 = !DILocation(line: 15, column: 1, scope: !26) |
| 192 | !35 = !DILocation(line: 16, column: 1, scope: !26) |
| 193 | !36 = !DILocation(line: 17, column: 1, scope: !26) |
| 194 | !37 = !DILocation(line: 18, column: 1, scope: !26) |
| 195 | !38 = !DILocation(line: 19, column: 1, scope: !26) |
| 196 | !39 = !DILocation(line: 20, column: 1, scope: !26) |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 197 | !40 = distinct !DISubprogram(name: "invoke_phi", linkageName: "invoke_phi", scope: null, file: !1, line: 21, type: !6, isLocal: false, isDefinition: true, scopeLine: 21, isOptimized: true, unit: !0, retainedNodes: !41) |
Reid Kleckner | 3a7a2e4 | 2018-03-14 21:54:21 +0000 | [diff] [blame] | 198 | !41 = !{!42, !44} |
| 199 | !42 = !DILocalVariable(name: "7", scope: !40, file: !1, line: 23, type: !43) |
| 200 | !43 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned) |
| 201 | !44 = !DILocalVariable(name: "8", scope: !40, file: !1, line: 26, type: !19) |
| 202 | !45 = !DILocation(line: 21, column: 1, scope: !40) |
| 203 | !46 = !DILocation(line: 22, column: 1, scope: !40) |
| 204 | !47 = !DILocation(line: 23, column: 1, scope: !40) |
| 205 | !48 = !DILocation(line: 24, column: 1, scope: !40) |
| 206 | !49 = !DILocation(line: 25, column: 1, scope: !40) |
| 207 | !50 = !DILocation(line: 26, column: 1, scope: !40) |
| 208 | !51 = !DILocation(line: 27, column: 1, scope: !40) |
| 209 | !52 = !{i32 2, !"Dwarf Version", i32 4} |
| 210 | !53 = !{i32 2, !"Debug Info Version", i32 3} |