; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes
; RUN: opt < %s -passes='loop-mssa(licm)' -S | FileCheck %s
; RUN: opt < %s -passes='loop-mssa(licm)' -S --try-experimental-debuginfo-iterators | FileCheck %s
; RUN: opt -aa-pipeline=tbaa,basic-aa -passes='require<aa>,require<target-ir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' -S %s | FileCheck %s
; RUN: opt -aa-pipeline=tbaa,basic-aa -passes='require<aa>,require<target-ir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' -S %s --try-experimental-debuginfo-iterators| FileCheck %s
;
; Test that when we sink the store into the "Out" block, it lands in front of
; the dbg.value that we've left there.
;
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
@X = global i32 7 ; <ptr> [#uses=4]
declare void @llvm.dbg.value(metadata, metadata, metadata)
define void @test1(i32 %i) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: Entry:
; CHECK-NEXT: [[X_PROMOTED:%.*]] = load i32, ptr @X, align 4
; CHECK-NEXT: br label [[LOOP:%.*]], !dbg [[DBG5:![0-9]+]]
; CHECK: Loop:
; CHECK-NEXT: [[X21:%.*]] = phi i32 [ [[X_PROMOTED]], [[ENTRY:%.*]] ], [ [[X2:%.*]], [[LOOP]] ], !dbg [[DBG5]]
; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[X2]] = add i32 [[X21]], 1, !dbg [[DBG5]]
; CHECK-NEXT: [[NEXT]] = add i32 [[J]], 1, !dbg [[DBG5]]
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[NEXT]], 0, !dbg [[DBG5]]
; CHECK-NEXT: br i1 [[COND]], label [[OUT:%.*]], label [[LOOP]], !dbg [[DBG5]]
; CHECK: Out:
; CHECK-NEXT: [[X2_LCSSA:%.*]] = phi i32 [ [[X2]], [[LOOP]] ]
; CHECK-NEXT: store i32 [[X2_LCSSA]], ptr @X, align 4, !dbg [[DBG5]]
; CHECK-NEXT: #dbg_value(i32 0, [[META12:![0-9]+]], !DIExpression(), [[DBG5]])
; CHECK-NEXT: ret void, !dbg [[DBG5]]
;
Entry:
br label %Loop, !dbg !16
Loop:
%j = phi i32 [ 0, %Entry ], [ %Next, %Loop ]
%x = load i32, ptr @X, !dbg !16
%x2 = add i32 %x, 1, !dbg !16
store i32 %x2, ptr @X, !dbg !16
%Next = add i32 %j, 1, !dbg !16
%cond = icmp eq i32 %Next, 0, !dbg !16
br i1 %cond, label %Out, label %Loop, !dbg !16
Out:
tail call void @llvm.dbg.value(metadata i32 0, metadata !11, metadata !DIExpression()), !dbg !16
ret void, !dbg !16
}
!llvm.dbg.cu = !{!0}
!llvm.debugify = !{!2, !3}
!llvm.module.flags = !{!4}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
!1 = !DIFile(filename: "dbg-value-sink.ll", directory: "/")
!2 = !{i32 9}
!3 = !{i32 5}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
!6 = !DISubroutineType(types: !7)
!7 = !{}
!8 = !{!9, !11, !12, !13, !14}
!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 2, type: !10)
!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
!11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 3, type: !10)
!12 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 4, type: !10)
!13 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 6, type: !10)
!14 = !DILocalVariable(name: "5", scope: !5, file: !1, line: 7, type: !15)
!15 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned)
!16 = !DILocation(line: 1, column: 1, scope: !5)
!17 = !DILocation(line: 2, column: 1, scope: !5)
!18 = !DILocation(line: 3, column: 1, scope: !5)
!19 = !DILocation(line: 4, column: 1, scope: !5)
!20 = !DILocation(line: 5, column: 1, scope: !5)
!21 = !DILocation(line: 6, column: 1, scope: !5)
!22 = !DILocation(line: 7, column: 1, scope: !5)
!23 = !DILocation(line: 8, column: 1, scope: !5)
!24 = !DILocation(line: 9, column: 1, scope: !5)