1 ; RUN: opt %s -passes='loop(indvars),verify' -S -o - | FileCheck %s
3 ; Hand-reduced from this example:
7 ; int main( int argc, char **argv )
9 ; for( int ArgIndex = 1; ArgIndex < argc; ArgIndex += 1 )
11 ; printf("\n Argument %d: %s\n", ArgIndex, argv[ArgIndex] );
15 ; clang++ -g -O -mllvm -disable-llvm-optzns -gno-column-info
16 ; opt -passes=mem2reg -scalar-evolution
19 ; CHECK: llvm.dbg.value(metadata i32 1, metadata [[METADATA_IDX1:![0-9]+]]
20 ; CHECK: %[[VAR_NAME:.*]] = add nuw nsw i64
21 ; CHECK: llvm.dbg.value(metadata i64 %[[VAR_NAME]], metadata [[METADATA_IDX1]], metadata !DIExpression())
22 ; CHECK: DICompileUnit
23 ; CHECK: [[METADATA_IDX1]] = !DILocalVariable(name: "ArgIndex"
25 source_filename = "test.cpp"
26 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
27 target triple = "x86_64-unknown-linux-gnu"
29 @.str = private unnamed_addr constant [20 x i8] c"\0A Argument %d: %s\0A\00", align 1
31 define dso_local i32 @main(i32 %argc, ptr %argv) !dbg !7 {
33 call void @llvm.dbg.value(metadata i32 %argc, metadata !15, metadata !DIExpression()), !dbg !19
34 call void @llvm.dbg.value(metadata ptr %argv, metadata !16, metadata !DIExpression()), !dbg !19
35 call void @llvm.dbg.value(metadata i32 1, metadata !17, metadata !DIExpression()), !dbg !19
36 br label %for.cond, !dbg !19
38 for.cond: ; preds = %for.inc, %entry
39 %ArgIndex.0 = phi i32 [ 1, %entry ], [ %add, %for.inc ], !dbg !19
40 call void @llvm.dbg.value(metadata i32 %ArgIndex.0, metadata !17, metadata !DIExpression()), !dbg !19
41 %cmp = icmp slt i32 %ArgIndex.0, %argc, !dbg !19
42 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !19
44 for.cond.cleanup: ; preds = %for.cond
47 for.body: ; preds = %for.cond
48 %idxprom = sext i32 %ArgIndex.0 to i64, !dbg !19
49 %arrayidx = getelementptr inbounds ptr, ptr %argv, i64 %idxprom, !dbg !19
50 %0 = load ptr, ptr %arrayidx, align 8, !dbg !19
51 %call = call i32 (ptr, ...) @printf(ptr @.str, i32 %ArgIndex.0, ptr %0), !dbg !19
52 br label %for.inc, !dbg !19
54 for.inc: ; preds = %for.body
55 %add = add nsw i32 %ArgIndex.0, 1, !dbg !19
56 call void @llvm.dbg.value(metadata i32 %add, metadata !17, metadata !DIExpression()), !dbg !19
57 br label %for.cond, !dbg !19, !llvm.loop !19
59 for.end: ; preds = %for.cond.cleanup
63 declare dso_local i32 @printf(ptr, ...)
65 declare void @llvm.dbg.value(metadata, metadata, metadata)
68 !llvm.module.flags = !{!3, !4, !5}
71 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
72 !1 = !DIFile(filename: "test.cpp", directory: "")
74 !3 = !{i32 2, !"Dwarf Version", i32 4}
75 !4 = !{i32 2, !"Debug Info Version", i32 3}
76 !5 = !{i32 1, !"wchar_size", i32 4}
78 !7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)
79 !8 = !DISubroutineType(types: !9)
81 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
82 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
83 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
84 !13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
85 !14 = !{!15, !16, !17}
86 !15 = !DILocalVariable(name: "argc", arg: 1, scope: !7, file: !1, line: 4, type: !10)
87 !16 = !DILocalVariable(name: "argv", arg: 2, scope: !7, file: !1, line: 4, type: !11)
88 !17 = !DILocalVariable(name: "ArgIndex", scope: !18, file: !1, line: 6, type: !10)
89 !18 = distinct !DILexicalBlock(scope: !7, file: !1, line: 6)
90 !19 = !DILocation(line: 0, scope: !7)