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 @.str1 = private unnamed_addr constant [2 x i8] c"+\00", align 1 48 @.str2 = 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 !30, metadata !DIExpression()), !dbg !47 56 tail call void @llvm.dbg.value(metadata i32 %param2, i64 0, metadata !31, metadata !DIExpression()), !dbg !47 57 tail call void @llvm.dbg.value(metadata i8* null, i64 0, metadata !32, metadata !DIExpression()), !dbg !49 58 %tobool = icmp eq i32 %param2, 0, !dbg !50 59 br i1 %tobool, label %if.end, label %if.then, !dbg !50 60 61 if.then: ; preds = %entry 62 %call = tail call i8* @_Z5i2stri(i32 %param2), !dbg !52 63 tail call void @llvm.dbg.value(metadata i8* %call, i64 0, metadata !32, metadata !DIExpression()), !dbg !49 64 br label %if.end, !dbg !54 65 66 if.end: ; preds = %entry, %if.then 67 tail call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !33, metadata !DIExpression()), !dbg !55 68 tail call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !56, metadata !DIExpression()), !dbg !57 69 tail call void @llvm.dbg.value(metadata !58, i64 0, metadata !59, metadata !DIExpression()), !dbg !60 70 %arraydecay.i = getelementptr inbounds %struct.AAA3, %struct.AAA3* %var1, i64 0, i32 0, i64 0, !dbg !61 71 call void @_Z3fooPcjPKc(i8* %arraydecay.i, i32 4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)), !dbg !61 72 call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !34, metadata !DIExpression()), !dbg !63 73 call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !64, metadata !DIExpression()), !dbg !65 74 call void @llvm.dbg.value(metadata !58, i64 0, metadata !66, metadata !DIExpression()), !dbg !67 75 %arraydecay.i5 = getelementptr inbounds %struct.AAA3, %struct.AAA3* %var2, i64 0, i32 0, i64 0, !dbg !68 76 call void @_Z3fooPcjPKc(i8* %arraydecay.i5, i32 4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)), !dbg !68 77 %tobool1 = icmp eq i32 %param1, 0, !dbg !69 78 call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !34, metadata !DIExpression()), !dbg !63 79 br i1 %tobool1, label %if.else, label %if.then2, !dbg !69 80 81 if.then2: ; preds = %if.end 82 call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !71, metadata !DIExpression()), !dbg !73 83 call void @llvm.dbg.value(metadata !74, i64 0, metadata !75, metadata !DIExpression()), !dbg !76 84 call void @_Z3fooPcjPKc(i8* %arraydecay.i5, i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str1, i64 0, i64 0)), !dbg !76 85 br label %if.end3, !dbg !72 86 87 if.else: ; preds = %if.end 88 call void @llvm.dbg.value(metadata %struct.AAA3* %var2, i64 0, metadata !77, metadata !DIExpression()), !dbg !79 89 call void @llvm.dbg.value(metadata !80, i64 0, metadata !81, metadata !DIExpression()), !dbg !82 90 call void @_Z3fooPcjPKc(i8* %arraydecay.i5, i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str2, i64 0, i64 0)), !dbg !82 91 br label %if.end3 92 93 if.end3: ; preds = %if.else, %if.then2 94 call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !33, metadata !DIExpression()), !dbg !55 95 call void @llvm.dbg.value(metadata %struct.AAA3* %var1, i64 0, metadata !83, metadata !DIExpression()), !dbg !85 96 call void @llvm.dbg.value(metadata !58, i64 0, metadata !86, metadata !DIExpression()), !dbg !87 97 call void @_Z3fooPcjPKc(i8* %arraydecay.i, i32 4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)), !dbg !87 98 ret void, !dbg !88 99 } 100 101 declare i8* @_Z5i2stri(i32) #1 102 103 declare void @_Z3fooPcjPKc(i8*, i32, i8*) #1 104 105 ; Function Attrs: nounwind readnone 106 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2 107 108 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 109 attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 110 attributes #2 = { nounwind readnone } 111 112 !llvm.dbg.cu = !{!0} 113 !llvm.module.flags = !{!44, !45} 114 !llvm.ident = !{!46} 115 116 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !3, subprograms: !23, globals: !2, imports: !2) 117 !1 = !DIFile(filename: "dbg-changes-codegen-branch-folding.cpp", directory: "/tmp/dbginfo") 118 !2 = !{} 119 !3 = !{!4} 120 !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "AAA3", line: 4, size: 32, align: 8, file: !1, elements: !5, identifier: "_ZTS4AAA3") 121 !5 = !{!6, !11, !17, !18} 122 !6 = !DIDerivedType(tag: DW_TAG_member, name: "text", line: 8, size: 32, align: 8, file: !1, scope: !"_ZTS4AAA3", baseType: !7) 123 !7 = !DICompositeType(tag: DW_TAG_array_type, size: 32, align: 8, baseType: !8, elements: !9) 124 !8 = !DIBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) 125 !9 = !{!10} 126 !10 = !DISubrange(count: 4) 127 !11 = !DISubprogram(name: "AAA3", line: 5, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 5, file: !1, scope: !"_ZTS4AAA3", type: !12) 128 !12 = !DISubroutineType(types: !13) 129 !13 = !{null, !14, !15} 130 !14 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !"_ZTS4AAA3") 131 !15 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !16) 132 !16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8) 133 !17 = !DISubprogram(name: "operator=", linkageName: "_ZN4AAA3aSEPKc", line: 6, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 6, file: !1, scope: !"_ZTS4AAA3", type: !12) 134 !18 = !DISubprogram(name: "operator const char *", linkageName: "_ZNK4AAA3cvPKcEv", line: 7, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 7, file: !1, scope: !"_ZTS4AAA3", type: !19) 135 !19 = !DISubroutineType(types: !20) 136 !20 = !{!15, !21} 137 !21 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !22) 138 !22 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !"_ZTS4AAA3") 139 !23 = !{!24, !35, !40} 140 !24 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barii", line: 11, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 11, file: !1, scope: !25, type: !26, variables: !29) 141 !25 = !DIFile(filename: "dbg-changes-codegen-branch-folding.cpp", directory: "/tmp/dbginfo") 142 !26 = !DISubroutineType(types: !27) 143 !27 = !{null, !28, !28} 144 !28 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 145 !29 = !{!30, !31, !32, !33, !34} 146 !30 = !DILocalVariable(name: "param1", line: 11, arg: 1, scope: !24, file: !25, type: !28) 147 !31 = !DILocalVariable(name: "param2", line: 11, arg: 2, scope: !24, file: !25, type: !28) 148 !32 = !DILocalVariable(name: "temp", line: 12, scope: !24, file: !25, type: !15) 149 !33 = !DILocalVariable(name: "var1", line: 17, scope: !24, file: !25, type: !"_ZTS4AAA3") 150 !34 = !DILocalVariable(name: "var2", line: 18, scope: !24, file: !25, type: !"_ZTS4AAA3") 151 !35 = distinct !DISubprogram(name: "operator=", linkageName: "_ZN4AAA3aSEPKc", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 6, file: !1, scope: !"_ZTS4AAA3", type: !12, declaration: !17, variables: !36) 152 !36 = !{!37, !39} 153 !37 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !35, type: !38) 154 !38 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !"_ZTS4AAA3") 155 !39 = !DILocalVariable(name: "value", line: 6, arg: 2, scope: !35, file: !25, type: !15) 156 !40 = distinct !DISubprogram(name: "AAA3", linkageName: "_ZN4AAA3C2EPKc", line: 5, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 5, file: !1, scope: !"_ZTS4AAA3", type: !12, declaration: !11, variables: !41) 157 !41 = !{!42, !43} 158 !42 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !40, type: !38) 159 !43 = !DILocalVariable(name: "value", line: 5, arg: 2, scope: !40, file: !25, type: !15) 160 !44 = !{i32 2, !"Dwarf Version", i32 4} 161 !45 = !{i32 2, !"Debug Info Version", i32 3} 162 !46 = !{!"clang version 3.5.0 "} 163 !47 = !DILocation(line: 11, scope: !24) 164 !48 = !{i8* null} 165 !49 = !DILocation(line: 12, scope: !24) 166 !50 = !DILocation(line: 14, scope: !51) 167 !51 = distinct !DILexicalBlock(line: 14, column: 0, file: !1, scope: !24) 168 !52 = !DILocation(line: 15, scope: !53) 169 !53 = distinct !DILexicalBlock(line: 14, column: 0, file: !1, scope: !51) 170 !54 = !DILocation(line: 16, scope: !53) 171 !55 = !DILocation(line: 17, scope: !24) 172 !56 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !40, type: !38) 173 !57 = !DILocation(line: 0, scope: !40, inlinedAt: !55) 174 !58 = !{i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)} 175 !59 = !DILocalVariable(name: "value", line: 5, arg: 2, scope: !40, file: !25, type: !15) 176 !60 = !DILocation(line: 5, scope: !40, inlinedAt: !55) 177 !61 = !DILocation(line: 5, scope: !62, inlinedAt: !55) 178 !62 = distinct !DILexicalBlock(line: 5, column: 0, file: !1, scope: !40) 179 !63 = !DILocation(line: 18, scope: !24) 180 !64 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !40, type: !38) 181 !65 = !DILocation(line: 0, scope: !40, inlinedAt: !63) 182 !66 = !DILocalVariable(name: "value", line: 5, arg: 2, scope: !40, file: !25, type: !15) 183 !67 = !DILocation(line: 5, scope: !40, inlinedAt: !63) 184 !68 = !DILocation(line: 5, scope: !62, inlinedAt: !63) 185 !69 = !DILocation(line: 20, scope: !70) 186 !70 = distinct !DILexicalBlock(line: 20, column: 0, file: !1, scope: !24) 187 !71 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !35, type: !38) 188 !72 = !DILocation(line: 21, scope: !70) 189 !73 = !DILocation(line: 0, scope: !35, inlinedAt: !72) 190 !74 = !{i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str1, i64 0, i64 0)} 191 !75 = !DILocalVariable(name: "value", line: 6, arg: 2, scope: !35, file: !25, type: !15) 192 !76 = !DILocation(line: 6, scope: !35, inlinedAt: !72) 193 !77 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !35, type: !38) 194 !78 = !DILocation(line: 23, scope: !70) 195 !79 = !DILocation(line: 0, scope: !35, inlinedAt: !78) 196 !80 = !{i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str2, i64 0, i64 0)} 197 !81 = !DILocalVariable(name: "value", line: 6, arg: 2, scope: !35, file: !25, type: !15) 198 !82 = !DILocation(line: 6, scope: !35, inlinedAt: !78) 199 !83 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !35, type: !38) 200 !84 = !DILocation(line: 24, scope: !24) 201 !85 = !DILocation(line: 0, scope: !35, inlinedAt: !84) 202 !86 = !DILocalVariable(name: "value", line: 6, arg: 2, scope: !35, file: !25, type: !15) 203 !87 = !DILocation(line: 6, scope: !35, inlinedAt: !84) 204 !88 = !DILocation(line: 25, scope: !24) 205