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