247 lines · plain
1; RUN: llc -O0 < %s | FileCheck %s2 3target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"4target triple = "i386-linux-gnu"5 6; Try some simple cases that show how local value sinking improves line tables.7 8@sink_across = external dso_local global i329 10declare void @simple_callee(i32, i32)11 12define void @simple() !dbg !5 {13 store i32 44, ptr @sink_across, !dbg !714 call void @simple_callee(i32 13, i32 55), !dbg !815 ret void, !dbg !916}17 18; CHECK-LABEL: simple:19; CHECK-NOT: movl $13,20; CHECK: .loc 1 1 1 prologue_end21; CHECK: movl $44, sink_across22; CHECK: .loc 1 2 123; CHECK: movl $13,24; CHECK: movl $55,25; CHECK: calll simple_callee26 27declare void @simple_reg_callee(i32 inreg, i32 inreg)28 29define void @simple_reg() !dbg !10 {30 store i32 44, ptr @sink_across, !dbg !1131 call void @simple_reg_callee(i32 inreg 13, i32 inreg 55), !dbg !1232 ret void, !dbg !1333}34 35; CHECK-LABEL: simple_reg:36; CHECK: .loc 1 4 1 prologue_end37; CHECK: movl $44, sink_across38; CHECK: .loc 1 5 139; CHECK: movl $13,40; CHECK: movl $55,41; CHECK: calll simple_reg_callee42 43; There are two interesting cases where local values have no uses but are not44; dead: when the local value is directly used by a phi, and when the local45; value is used by a no-op cast instruction. In these cases, we get side tables46; referring to the local value vreg that we need to check.47 48define ptr @phi_const(i32 %c) !dbg !14 {49entry:50 %tobool = icmp eq i32 %c, 0, !dbg !2051 call void @llvm.dbg.value(metadata i1 %tobool, metadata !16, metadata !DIExpression()), !dbg !2052 br i1 %tobool, label %if.else, label %if.then, !dbg !2153 54if.then: ; preds = %entry55 br label %if.end, !dbg !2256 57if.else: ; preds = %entry58 br label %if.end, !dbg !2359 60if.end: ; preds = %if.else, %if.then61 %r.0 = phi ptr [ inttoptr (i32 42 to ptr), %if.then ], [ inttoptr (i32 1 to ptr), %if.else ], !dbg !2462 call void @llvm.dbg.value(metadata ptr %r.0, metadata !18, metadata !DIExpression()), !dbg !2463 ret ptr %r.0, !dbg !2564}65 66; CHECK-LABEL: phi_const:67; CHECK: # %entry68; CHECK: cmpl $0,69; CHECK: # %if.then70; CHECK: movl $42,71; CHECK: jmp72; CHECK: # %if.else73; CHECK: movl $1,74; CHECK: # %if.end75 76define ptr @phi_const_cast(i32 %c) !dbg !26 {77entry:78 %tobool = icmp eq i32 %c, 0, !dbg !3279 call void @llvm.dbg.value(metadata i1 %tobool, metadata !28, metadata !DIExpression()), !dbg !3280 br i1 %tobool, label %if.else, label %if.then, !dbg !3381 82if.then: ; preds = %entry83 %v42 = inttoptr i32 42 to ptr, !dbg !3484 call void @llvm.dbg.value(metadata ptr %v42, metadata !29, metadata !DIExpression()), !dbg !3485 br label %if.end, !dbg !3586 87if.else: ; preds = %entry88 %v1 = inttoptr i32 1 to ptr, !dbg !3689 call void @llvm.dbg.value(metadata ptr %v1, metadata !30, metadata !DIExpression()), !dbg !3690 br label %if.end, !dbg !3791 92if.end: ; preds = %if.else, %if.then93 %r.0 = phi ptr [ %v42, %if.then ], [ %v1, %if.else ], !dbg !3894 call void @llvm.dbg.value(metadata ptr %r.0, metadata !31, metadata !DIExpression()), !dbg !3895 ret ptr %r.0, !dbg !3996}97 98; CHECK-LABEL: phi_const_cast:99; CHECK: # %entry100; CHECK: cmpl $0,101; CHECK: # %if.then102; CHECK: movl $42, %[[REG:[a-z]+]]103; CHECK: #DEBUG_VALUE: phi_const_cast:4 <- $[[REG]]104; CHECK: jmp105; CHECK: # %if.else106; CHECK: movl $1, %[[REG:[a-z]+]]107; CHECK: #DEBUG_VALUE: phi_const_cast:5 <- $[[REG]]108; CHECK: # %if.end109 110declare void @may_throw() local_unnamed_addr #1111 112declare i32 @__gxx_personality_v0(...)113 114define i32 @invoke_phi() personality ptr @__gxx_personality_v0 {115entry:116 store i32 42, ptr @sink_across117 invoke void @may_throw()118 to label %try.cont unwind label %lpad119 120lpad: ; preds = %entry121 %0 = landingpad { ptr, i32 }122 catch ptr null123 store i32 42, ptr @sink_across124 br label %try.cont125 126try.cont: ; preds = %entry, %lpad127 %r.0 = phi i32 [ 13, %entry ], [ 55, %lpad ]128 ret i32 %r.0129}130 131; The constant materialization should be *after* the stores to sink_across, but132; before any EH_LABEL.133 134; CHECK-LABEL: invoke_phi:135; CHECK: movl $42, sink_across136; CHECK: movl $13, %{{[a-z]*}}137; CHECK: .Ltmp{{.*}}:138; CHECK: calll may_throw139; CHECK: .Ltmp{{.*}}:140; CHECK: jmp .LBB{{.*}}141; CHECK: .LBB{{.*}}: # %lpad142; CHECK: movl $42, sink_across143; CHECK: movl $55, %{{[a-z]*}}144; CHECK: .LBB{{.*}}: # %try.cont145; CHECK: retl146 147 148define i32 @lpad_phi() personality ptr @__gxx_personality_v0 {149entry:150 store i32 42, ptr @sink_across151 invoke void @may_throw()152 to label %try.cont unwind label %lpad153 154lpad: ; preds = %entry155 %p = phi i32 [ 11, %entry ] ; Trivial, but -O0 keeps it156 %0 = landingpad { ptr, i32 }157 catch ptr null158 store i32 %p, ptr @sink_across159 br label %try.cont160 161try.cont: ; preds = %entry, %lpad162 %r.0 = phi i32 [ 13, %entry ], [ 55, %lpad ]163 ret i32 %r.0164}165 166; The constant materialization should be *after* the stores to sink_across, but167; before any EH_LABEL.168 169; CHECK-LABEL: lpad_phi:170; CHECK: movl $42, sink_across171; CHECK: movl $13, %{{[a-z]*}}172; CHECK: .Ltmp{{.*}}:173; CHECK: calll may_throw174; CHECK: .Ltmp{{.*}}:175; CHECK: jmp .LBB{{.*}}176; CHECK: .LBB{{.*}}: # %lpad177; CHECK-NEXT: .Ltmp{{.*}}:178; CHECK: movl {{.*}}, sink_across179; CHECK: movl $55, %{{[a-z]*}}180; CHECK: .LBB{{.*}}: # %try.cont181; CHECK: retl182 183 184; Function Attrs: nounwind readnone speculatable185declare void @llvm.dbg.value(metadata, metadata, metadata) #0186 187attributes #0 = { nounwind readnone speculatable }188 189!llvm.dbg.cu = !{!0}190!llvm.debugify = !{!3, !4}191!llvm.module.flags = !{!52, !53}192 193!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)194!1 = !DIFile(filename: "../llvm/test/CodeGen/X86/sink-local-value.ll", directory: "/")195!2 = !{}196!3 = !{i32 27}197!4 = !{i32 8}198!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)199!6 = !DISubroutineType(types: !2)200!7 = !DILocation(line: 1, column: 1, scope: !5)201!8 = !DILocation(line: 2, column: 1, scope: !5)202!9 = !DILocation(line: 3, column: 1, scope: !5)203!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)204!11 = !DILocation(line: 4, column: 1, scope: !10)205!12 = !DILocation(line: 5, column: 1, scope: !10)206!13 = !DILocation(line: 6, column: 1, scope: !10)207!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)208!15 = !{!16, !18}209!16 = !DILocalVariable(name: "1", scope: !14, file: !1, line: 7, type: !17)210!17 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned)211!18 = !DILocalVariable(name: "2", scope: !14, file: !1, line: 11, type: !19)212!19 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)213!20 = !DILocation(line: 7, column: 1, scope: !14)214!21 = !DILocation(line: 8, column: 1, scope: !14)215!22 = !DILocation(line: 9, column: 1, scope: !14)216!23 = !DILocation(line: 10, column: 1, scope: !14)217!24 = !DILocation(line: 11, column: 1, scope: !14)218!25 = !DILocation(line: 12, column: 1, scope: !14)219!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)220!27 = !{!28, !29, !30, !31}221!28 = !DILocalVariable(name: "3", scope: !26, file: !1, line: 13, type: !17)222!29 = !DILocalVariable(name: "4", scope: !26, file: !1, line: 15, type: !19)223!30 = !DILocalVariable(name: "5", scope: !26, file: !1, line: 17, type: !19)224!31 = !DILocalVariable(name: "6", scope: !26, file: !1, line: 19, type: !19)225!32 = !DILocation(line: 13, column: 1, scope: !26)226!33 = !DILocation(line: 14, column: 1, scope: !26)227!34 = !DILocation(line: 15, column: 1, scope: !26)228!35 = !DILocation(line: 16, column: 1, scope: !26)229!36 = !DILocation(line: 17, column: 1, scope: !26)230!37 = !DILocation(line: 18, column: 1, scope: !26)231!38 = !DILocation(line: 19, column: 1, scope: !26)232!39 = !DILocation(line: 20, column: 1, scope: !26)233!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)234!41 = !{!42, !44}235!42 = !DILocalVariable(name: "7", scope: !40, file: !1, line: 23, type: !43)236!43 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)237!44 = !DILocalVariable(name: "8", scope: !40, file: !1, line: 26, type: !19)238!45 = !DILocation(line: 21, column: 1, scope: !40)239!46 = !DILocation(line: 22, column: 1, scope: !40)240!47 = !DILocation(line: 23, column: 1, scope: !40)241!48 = !DILocation(line: 24, column: 1, scope: !40)242!49 = !DILocation(line: 25, column: 1, scope: !40)243!50 = !DILocation(line: 26, column: 1, scope: !40)244!51 = !DILocation(line: 27, column: 1, scope: !40)245!52 = !{i32 2, !"Dwarf Version", i32 4}246!53 = !{i32 2, !"Debug Info Version", i32 3}247