Reapply r257105 "[Verifier] Check that debug values have proper size"
[oota-llvm.git] / test / CodeGen / X86 / dbg-changes-codegen-branch-folding.ll
1 ; RUN: llc -march=x86-64 -mtriple=x86_64-linux < %s | FileCheck %s
2 ; RUN: opt -strip-debug < %s | llc -march=x86-64 -mtriple=x86_64-linux | FileCheck %s
3 ; http://llvm.org/PR19051. Minor code-motion difference with -g.
4 ; Presence of debug info shouldn't affect the codegen. Make sure that
5 ; we generated the same code sequence with and without debug info. 
6 ;
7 ; CHECK:      callq   _Z3fooPcjPKc
8 ; CHECK:      callq   _Z3fooPcjPKc
9 ; CHECK:      leaq    (%rsp), %rdi
10 ; CHECK:      movl    $4, %esi
11 ; CHECK:      testl   {{%[a-z]+}}, {{%[a-z]+}}
12 ; CHECK:      je     .LBB0_4
13
14 ; Regenerate test with this command: 
15 ;   clang++ -emit-llvm -S -O2 -g
16 ; from this source:
17 ;
18 ; extern void foo(char *dst,unsigned siz,const char *src);
19 ; extern const char * i2str(int);
20 ;
21 ; struct AAA3 {
22 ;  AAA3(const char *value) { foo(text,sizeof(text),value);}
23 ;  void operator=(const char *value) { foo(text,sizeof(text),value);}
24 ;  operator const char*() const { return text;}
25 ;  char text[4];
26 ; };
27 ;
28 ; void bar (int param1,int param2)  {
29 ;   const char * temp(0);
30 ;
31 ;   if (param2) {
32 ;     temp = i2str(param2);
33 ;   }
34 ;   AAA3 var1("");
35 ;   AAA3 var2("");
36 ;
37 ;   if (param1)
38 ;     var2 = "+";
39 ;   else
40 ;     var2 = "-";
41 ;   var1 = "";
42 ; }
43
44 %struct.AAA3 = type { [4 x i8] }
45
46 @.str = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
47 @.str.1 = private unnamed_addr constant [2 x i8] c"+\00", align 1
48 @.str.2 = private unnamed_addr constant [2 x i8] c"-\00", align 1
49
50 ; Function Attrs: uwtable
51 define void @_Z3barii(i32 %param1, i32 %param2) #0 !dbg !24 {
52 entry:
53   %var1 = alloca %struct.AAA3, align 1
54   %var2 = alloca %struct.AAA3, align 1
55   tail call void @llvm.dbg.value(metadata i32 %param1, i64 0, metadata !29, metadata !46), !dbg !47
56   tail call void @llvm.dbg.value(metadata i32 %param2, i64 0, metadata !30, metadata !46), !dbg !48
57   tail call void @llvm.dbg.value(metadata i8* null, i64 0, metadata !31, metadata !46), !dbg !49
58   %tobool = icmp eq i32 %param2, 0, !dbg !50
59   br i1 %tobool, label %if.end, label %if.then, !dbg !52
60
61 if.then:                                          ; preds = %entry
62   %call = tail call i8* @_Z5i2stri(i32 %param2), !dbg !53
63   tail call void @llvm.dbg.value(metadata i8* %call, i64 0, metadata !31, metadata !46), !dbg !49
64   br label %if.end, !dbg !55
65
66 if.end:                                           ; preds = %entry, %if.then
67   %0 = getelementptr inbounds %struct.AAA3, %struct.AAA3* %var1, i64 0, i32 0, i64 0, !dbg !56
68   call void @llvm.lifetime.start(i64 4, i8* %0) #4, !dbg !56
69   tail call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !32, metadata !57), !dbg !58
70   tail call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !36, metadata !46), !dbg !59
71   tail call void @llvm.dbg.value(metadata i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 0, metadata !38, metadata !46), !dbg !62
72   call void @_Z3fooPcjPKc(i8* %0, i32 4, i8* nonnull getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)), !dbg !63
73   %1 = getelementptr inbounds %struct.AAA3, %struct.AAA3* %var2, i64 0, i32 0, i64 0, !dbg !65
74   call void @llvm.lifetime.start(i64 4, i8* %1) #4, !dbg !65
75   call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !33, metadata !57), !dbg !66
76   call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !36, metadata !46), !dbg !67
77   call void @llvm.dbg.value(metadata i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 0, metadata !38, metadata !46), !dbg !69
78   call void @_Z3fooPcjPKc(i8* %1, i32 4, i8* nonnull getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)), !dbg !70
79   %tobool1 = icmp eq i32 %param1, 0, !dbg !71
80   call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !33, metadata !57), !dbg !66
81   call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !41, metadata !46), !dbg !73
82   br i1 %tobool1, label %if.else, label %if.then2, !dbg !75
83
84 if.then2:                                         ; preds = %if.end
85   call void @llvm.dbg.value(metadata i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i64 0, metadata !42, metadata !46), !dbg !76
86   call void @_Z3fooPcjPKc(i8* %1, i32 4, i8* nonnull getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)), !dbg !78
87   br label %if.end3, !dbg !79
88
89 if.else:                                          ; preds = %if.end
90   call void @llvm.dbg.value(metadata i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i64 0, metadata !42, metadata !46), !dbg !80
91   call void @_Z3fooPcjPKc(i8* %1, i32 4, i8* nonnull getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)), !dbg !81
92   br label %if.end3
93
94 if.end3:                                          ; preds = %if.else, %if.then2
95   call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !32, metadata !57), !dbg !58
96   call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !41, metadata !46), !dbg !82
97   call void @llvm.dbg.value(metadata i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64 0, metadata !42, metadata !46), !dbg !84
98   call void @_Z3fooPcjPKc(i8* %0, i32 4, i8* nonnull getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)), !dbg !85
99   call void @llvm.lifetime.end(i64 4, i8* %1) #4, !dbg !86
100   call void @llvm.lifetime.end(i64 4, i8* %0) #4, !dbg !87
101   ret void, !dbg !86
102 }
103
104 ; Function Attrs: argmemonly nounwind
105 declare void @llvm.lifetime.start(i64, i8* nocapture) #1
106
107 declare i8* @_Z5i2stri(i32) #2
108
109 ; Function Attrs: argmemonly nounwind
110 declare void @llvm.lifetime.end(i64, i8* nocapture) #1
111
112 declare void @_Z3fooPcjPKc(i8*, i32, i8*) #2
113
114 ; Function Attrs: nounwind readnone
115 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3
116
117 attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
118 attributes #1 = { argmemonly nounwind }
119 attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
120 attributes #3 = { nounwind readnone }
121 attributes #4 = { nounwind }
122
123 !llvm.dbg.cu = !{!0}
124 !llvm.module.flags = !{!43, !44}
125 !llvm.ident = !{!45}
126
127 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 255993) (llvm/trunk 256074)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !3, subprograms: !23)
128 !1 = !DIFile(filename: "test.cpp", directory: "/mnt/extra")
129 !2 = !{}
130 !3 = !{!4}
131 !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "AAA3", file: !1, line: 4, size: 32, align: 8, elements: !5, identifier: "_ZTS4AAA3")
132 !5 = !{!6, !11, !17, !18}
133 !6 = !DIDerivedType(tag: DW_TAG_member, name: "text", scope: !"_ZTS4AAA3", file: !1, line: 8, baseType: !7, size: 32, align: 8)
134 !7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 32, align: 8, elements: !9)
135 !8 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
136 !9 = !{!10}
137 !10 = !DISubrange(count: 4)
138 !11 = !DISubprogram(name: "AAA3", scope: !"_ZTS4AAA3", file: !1, line: 5, type: !12, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true)
139 !12 = !DISubroutineType(types: !13)
140 !13 = !{null, !14, !15}
141 !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !"_ZTS4AAA3", size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
142 !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64, align: 64)
143 !16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)
144 !17 = !DISubprogram(name: "operator=", linkageName: "_ZN4AAA3aSEPKc", scope: !"_ZTS4AAA3", file: !1, line: 6, type: !12, isLocal: false, isDefinition: false, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true)
145 !18 = !DISubprogram(name: "operator const char *", linkageName: "_ZNK4AAA3cvPKcEv", scope: !"_ZTS4AAA3", file: !1, line: 7, type: !19, isLocal: false, isDefinition: false, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: true)
146 !19 = !DISubroutineType(types: !20)
147 !20 = !{!15, !21}
148 !21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
149 !22 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !"_ZTS4AAA3")
150 !23 = !{!24, !34, !39}
151 !24 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barii", scope: !1, file: !1, line: 11, type: !25, isLocal: false, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: true, variables: !28)
152 !25 = !DISubroutineType(types: !26)
153 !26 = !{null, !27, !27}
154 !27 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
155 !28 = !{!29, !30, !31, !32, !33}
156 !29 = !DILocalVariable(name: "param1", arg: 1, scope: !24, file: !1, line: 11, type: !27)
157 !30 = !DILocalVariable(name: "param2", arg: 2, scope: !24, file: !1, line: 11, type: !27)
158 !31 = !DILocalVariable(name: "temp", scope: !24, file: !1, line: 12, type: !15)
159 !32 = !DILocalVariable(name: "var1", scope: !24, file: !1, line: 17, type: !"_ZTS4AAA3")
160 !33 = !DILocalVariable(name: "var2", scope: !24, file: !1, line: 18, type: !"_ZTS4AAA3")
161 !34 = distinct !DISubprogram(name: "AAA3", linkageName: "_ZN4AAA3C2EPKc", scope: !"_ZTS4AAA3", file: !1, line: 5, type: !12, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, declaration: !11, variables: !35)
162 !35 = !{!36, !38}
163 !36 = !DILocalVariable(name: "this", arg: 1, scope: !34, type: !37, flags: DIFlagArtificial | DIFlagObjectPointer)
164 !37 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !"_ZTS4AAA3", size: 64, align: 64)
165 !38 = !DILocalVariable(name: "value", arg: 2, scope: !34, file: !1, line: 5, type: !15)
166 !39 = distinct !DISubprogram(name: "operator=", linkageName: "_ZN4AAA3aSEPKc", scope: !"_ZTS4AAA3", file: !1, line: 6, type: !12, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, declaration: !17, variables: !40)
167 !40 = !{!41, !42}
168 !41 = !DILocalVariable(name: "this", arg: 1, scope: !39, type: !37, flags: DIFlagArtificial | DIFlagObjectPointer)
169 !42 = !DILocalVariable(name: "value", arg: 2, scope: !39, file: !1, line: 6, type: !15)
170 !43 = !{i32 2, !"Dwarf Version", i32 4}
171 !44 = !{i32 2, !"Debug Info Version", i32 3}
172 !45 = !{!"clang version 3.8.0 (trunk 255993) (llvm/trunk 256074)"}
173 !46 = !DIExpression()
174 !47 = !DILocation(line: 11, column: 15, scope: !24)
175 !48 = !DILocation(line: 11, column: 26, scope: !24)
176 !49 = !DILocation(line: 12, column: 16, scope: !24)
177 !50 = !DILocation(line: 14, column: 7, scope: !51)
178 !51 = distinct !DILexicalBlock(scope: !24, file: !1, line: 14, column: 7)
179 !52 = !DILocation(line: 14, column: 7, scope: !24)
180 !53 = !DILocation(line: 15, column: 12, scope: !54)
181 !54 = distinct !DILexicalBlock(scope: !51, file: !1, line: 14, column: 15)
182 !55 = !DILocation(line: 16, column: 3, scope: !54)
183 !56 = !DILocation(line: 17, column: 3, scope: !24)
184 !57 = !DIExpression(DW_OP_deref)
185 !58 = !DILocation(line: 17, column: 8, scope: !24)
186 !59 = !DILocation(line: 0, scope: !34, inlinedAt: !60)
187 !60 = distinct !DILocation(line: 17, column: 8, scope: !61)
188 !61 = !DILexicalBlockFile(scope: !24, file: !1, discriminator: 1)
189 !62 = !DILocation(line: 5, column: 19, scope: !34, inlinedAt: !60)
190 !63 = !DILocation(line: 5, column: 28, scope: !64, inlinedAt: !60)
191 !64 = distinct !DILexicalBlock(scope: !34, file: !1, line: 5, column: 26)
192 !65 = !DILocation(line: 18, column: 3, scope: !24)
193 !66 = !DILocation(line: 18, column: 8, scope: !24)
194 !67 = !DILocation(line: 0, scope: !34, inlinedAt: !68)
195 !68 = distinct !DILocation(line: 18, column: 8, scope: !61)
196 !69 = !DILocation(line: 5, column: 19, scope: !34, inlinedAt: !68)
197 !70 = !DILocation(line: 5, column: 28, scope: !64, inlinedAt: !68)
198 !71 = !DILocation(line: 20, column: 7, scope: !72)
199 !72 = distinct !DILexicalBlock(scope: !24, file: !1, line: 20, column: 7)
200 !73 = !DILocation(line: 0, scope: !39, inlinedAt: !74)
201 !74 = distinct !DILocation(line: 23, column: 10, scope: !72)
202 !75 = !DILocation(line: 20, column: 7, scope: !24)
203 !76 = !DILocation(line: 6, column: 29, scope: !39, inlinedAt: !77)
204 !77 = distinct !DILocation(line: 21, column: 10, scope: !72)
205 !78 = !DILocation(line: 6, column: 38, scope: !39, inlinedAt: !77)
206 !79 = !DILocation(line: 21, column: 5, scope: !72)
207 !80 = !DILocation(line: 6, column: 29, scope: !39, inlinedAt: !74)
208 !81 = !DILocation(line: 6, column: 38, scope: !39, inlinedAt: !74)
209 !82 = !DILocation(line: 0, scope: !39, inlinedAt: !83)
210 !83 = distinct !DILocation(line: 24, column: 8, scope: !24)
211 !84 = !DILocation(line: 6, column: 29, scope: !39, inlinedAt: !83)
212 !85 = !DILocation(line: 6, column: 38, scope: !39, inlinedAt: !83)
213 !86 = !DILocation(line: 25, column: 1, scope: !24)
214 !87 = !DILocation(line: 25, column: 1, scope: !61)