Home | History | Annotate | Download | only in X86
      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 {
     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), !dbg !47
     56   tail call void @llvm.dbg.value(metadata !{i32 %param2}, i64 0, metadata !31), !dbg !47
     57   tail call void @llvm.dbg.value(metadata !48, i64 0, metadata !32), !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), !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), !dbg !55
     68   tail call void @llvm.dbg.value(metadata !{%struct.AAA3* %var1}, i64 0, metadata !56), !dbg !57
     69   tail call void @llvm.dbg.value(metadata !58, i64 0, metadata !59), !dbg !60
     70   %arraydecay.i = getelementptr inbounds %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]* @.str, i64 0, i64 0)), !dbg !61
     72   call void @llvm.dbg.value(metadata !{%struct.AAA3* %var2}, i64 0, metadata !34), !dbg !63
     73   call void @llvm.dbg.value(metadata !{%struct.AAA3* %var2}, i64 0, metadata !64), !dbg !65
     74   call void @llvm.dbg.value(metadata !58, i64 0, metadata !66), !dbg !67
     75   %arraydecay.i5 = getelementptr inbounds %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]* @.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), !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), !dbg !73
     83   call void @llvm.dbg.value(metadata !74, i64 0, metadata !75), !dbg !76
     84   call void @_Z3fooPcjPKc(i8* %arraydecay.i5, i32 4, i8* getelementptr inbounds ([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), !dbg !79
     89   call void @llvm.dbg.value(metadata !80, i64 0, metadata !81), !dbg !82
     90   call void @_Z3fooPcjPKc(i8* %arraydecay.i5, i32 4, i8* getelementptr inbounds ([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), !dbg !55
     95   call void @llvm.dbg.value(metadata !{%struct.AAA3* %var1}, i64 0, metadata !83), !dbg !85
     96   call void @llvm.dbg.value(metadata !58, i64 0, metadata !86), !dbg !87
     97   call void @_Z3fooPcjPKc(i8* %arraydecay.i, i32 4, i8* getelementptr inbounds ([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) #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 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.5.0 ", i1 true, metadata !"", i32 0, metadata !2, metadata !3, metadata !23, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/tmp/dbginfo/dbg-changes-codegen-branch-folding.cpp] [DW_LANG_C_plus_plus]
    117 !1 = metadata !{metadata !"dbg-changes-codegen-branch-folding.cpp", metadata !"/tmp/dbginfo"}
    118 !2 = metadata !{}
    119 !3 = metadata !{metadata !4}
    120 !4 = metadata !{i32 786451, metadata !1, null, metadata !"AAA3", i32 4, i64 32, i64 8, i32 0, i32 0, null, metadata !5, i32 0, null, null, metadata !"_ZTS4AAA3"} ; [ DW_TAG_structure_type ] [AAA3] [line 4, size 32, align 8, offset 0] [def] [from ]
    121 !5 = metadata !{metadata !6, metadata !11, metadata !17, metadata !18}
    122 !6 = metadata !{i32 786445, metadata !1, metadata !"_ZTS4AAA3", metadata !"text", i32 8, i64 32, i64 8, i64 0, i32 0, metadata !7} ; [ DW_TAG_member ] [text] [line 8, size 32, align 8, offset 0] [from ]
    123 !7 = metadata !{i32 786433, null, null, metadata !"", i32 0, i64 32, i64 8, i32 0, i32 0, metadata !8, metadata !9, i32 0, null, null, null} ; [ DW_TAG_array_type ] [line 0, size 32, align 8, offset 0] [from char]
    124 !8 = metadata !{i32 786468, null, null, metadata !"char", i32 0, i64 8, i64 8, i64 0, i32 0, i32 6} ; [ DW_TAG_base_type ] [char] [line 0, size 8, align 8, offset 0, enc DW_ATE_signed_char]
    125 !9 = metadata !{metadata !10}
    126 !10 = metadata !{i32 786465, i64 0, i64 4}        ; [ DW_TAG_subrange_type ] [0, 3]
    127 !11 = metadata !{i32 786478, metadata !1, metadata !"_ZTS4AAA3", metadata !"AAA3", metadata !"AAA3", metadata !"", i32 5, metadata !12, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 true, null, null, i32 0, null, i32 5} ; [ DW_TAG_subprogram ] [line 5] [AAA3]
    128 !12 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !13, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
    129 !13 = metadata !{null, metadata !14, metadata !15}
    130 !14 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !"_ZTS4AAA3"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from _ZTS4AAA3]
    131 !15 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !16} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from ]
    132 !16 = metadata !{i32 786470, null, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, metadata !8} ; [ DW_TAG_const_type ] [line 0, size 0, align 0, offset 0] [from char]
    133 !17 = metadata !{i32 786478, metadata !1, metadata !"_ZTS4AAA3", metadata !"operator=", metadata !"operator=", metadata !"_ZN4AAA3aSEPKc", i32 6, metadata !12, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 true, null, null, i32 0, null, i32 6} ; [ DW_TAG_subprogram ] [line 6] [operator=]
    134 !18 = metadata !{i32 786478, metadata !1, metadata !"_ZTS4AAA3", metadata !"operator const char *", metadata !"operator const char *", metadata !"_ZNK4AAA3cvPKcEv", i32 7, metadata !19, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 true, null, null, i32 0, null, i32 7} ; [ DW_TAG_subprogram ] [line 7] [operator const char *]
    135 !19 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !20, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
    136 !20 = metadata !{metadata !15, metadata !21}
    137 !21 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !22} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from ]
    138 !22 = metadata !{i32 786470, null, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, metadata !"_ZTS4AAA3"} ; [ DW_TAG_const_type ] [line 0, size 0, align 0, offset 0] [from _ZTS4AAA3]
    139 !23 = metadata !{metadata !24, metadata !35, metadata !40}
    140 !24 = metadata !{i32 786478, metadata !1, metadata !25, metadata !"bar", metadata !"bar", metadata !"_Z3barii", i32 11, metadata !26, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, void (i32, i32)* @_Z3barii, null, null, metadata !29, i32 11} ; [ DW_TAG_subprogram ] [line 11] [def] [bar]
    141 !25 = metadata !{i32 786473, metadata !1}         ; [ DW_TAG_file_type ] [/tmp/dbginfo/dbg-changes-codegen-branch-folding.cpp]
    142 !26 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !27, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
    143 !27 = metadata !{null, metadata !28, metadata !28}
    144 !28 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
    145 !29 = metadata !{metadata !30, metadata !31, metadata !32, metadata !33, metadata !34}
    146 !30 = metadata !{i32 786689, metadata !24, metadata !"param1", metadata !25, i32 16777227, metadata !28, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [param1] [line 11]
    147 !31 = metadata !{i32 786689, metadata !24, metadata !"param2", metadata !25, i32 33554443, metadata !28, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [param2] [line 11]
    148 !32 = metadata !{i32 786688, metadata !24, metadata !"temp", metadata !25, i32 12, metadata !15, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [temp] [line 12]
    149 !33 = metadata !{i32 786688, metadata !24, metadata !"var1", metadata !25, i32 17, metadata !"_ZTS4AAA3", i32 0, i32 0} ; [ DW_TAG_auto_variable ] [var1] [line 17]
    150 !34 = metadata !{i32 786688, metadata !24, metadata !"var2", metadata !25, i32 18, metadata !"_ZTS4AAA3", i32 0, i32 0} ; [ DW_TAG_auto_variable ] [var2] [line 18]
    151 !35 = metadata !{i32 786478, metadata !1, metadata !"_ZTS4AAA3", metadata !"operator=", metadata !"operator=", metadata !"_ZN4AAA3aSEPKc", i32 6, metadata !12, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, null, null, metadata !17, metadata !36, i32 6} ; [ DW_TAG_subprogram ] [line 6] [def] [operator=]
    152 !36 = metadata !{metadata !37, metadata !39}
    153 !37 = metadata !{i32 786689, metadata !35, metadata !"this", null, i32 16777216, metadata !38, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
    154 !38 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS4AAA3"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS4AAA3]
    155 !39 = metadata !{i32 786689, metadata !35, metadata !"value", metadata !25, i32 33554438, metadata !15, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [value] [line 6]
    156 !40 = metadata !{i32 786478, metadata !1, metadata !"_ZTS4AAA3", metadata !"AAA3", metadata !"AAA3", metadata !"_ZN4AAA3C2EPKc", i32 5, metadata !12, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, null, null, metadata !11, metadata !41, i32 5} ; [ DW_TAG_subprogram ] [line 5] [def] [AAA3]
    157 !41 = metadata !{metadata !42, metadata !43}
    158 !42 = metadata !{i32 786689, metadata !40, metadata !"this", null, i32 16777216, metadata !38, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
    159 !43 = metadata !{i32 786689, metadata !40, metadata !"value", metadata !25, i32 33554437, metadata !15, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [value] [line 5]
    160 !44 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
    161 !45 = metadata !{i32 2, metadata !"Debug Info Version", i32 1}
    162 !46 = metadata !{metadata !"clang version 3.5.0 "}
    163 !47 = metadata !{i32 11, i32 0, metadata !24, null}
    164 !48 = metadata !{i8* null}
    165 !49 = metadata !{i32 12, i32 0, metadata !24, null}
    166 !50 = metadata !{i32 14, i32 0, metadata !51, null}
    167 !51 = metadata !{i32 786443, metadata !1, metadata !24, i32 14, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/dbg-changes-codegen-branch-folding.cpp]
    168 !52 = metadata !{i32 15, i32 0, metadata !53, null}
    169 !53 = metadata !{i32 786443, metadata !1, metadata !51, i32 14, i32 0, i32 0, i32 1} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/dbg-changes-codegen-branch-folding.cpp]
    170 !54 = metadata !{i32 16, i32 0, metadata !53, null}
    171 !55 = metadata !{i32 17, i32 0, metadata !24, null}
    172 !56 = metadata !{i32 786689, metadata !40, metadata !"this", null, i32 16777216, metadata !38, i32 1088, metadata !55} ; [ DW_TAG_arg_variable ] [this] [line 0]
    173 !57 = metadata !{i32 0, i32 0, metadata !40, metadata !55}
    174 !58 = metadata !{i8* getelementptr inbounds ([1 x i8]* @.str, i64 0, i64 0)}
    175 !59 = metadata !{i32 786689, metadata !40, metadata !"value", metadata !25, i32 33554437, metadata !15, i32 0, metadata !55} ; [ DW_TAG_arg_variable ] [value] [line 5]
    176 !60 = metadata !{i32 5, i32 0, metadata !40, metadata !55}
    177 !61 = metadata !{i32 5, i32 0, metadata !62, metadata !55}
    178 !62 = metadata !{i32 786443, metadata !1, metadata !40, i32 5, i32 0, i32 0, i32 3} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/dbg-changes-codegen-branch-folding.cpp]
    179 !63 = metadata !{i32 18, i32 0, metadata !24, null}
    180 !64 = metadata !{i32 786689, metadata !40, metadata !"this", null, i32 16777216, metadata !38, i32 1088, metadata !63} ; [ DW_TAG_arg_variable ] [this] [line 0]
    181 !65 = metadata !{i32 0, i32 0, metadata !40, metadata !63}
    182 !66 = metadata !{i32 786689, metadata !40, metadata !"value", metadata !25, i32 33554437, metadata !15, i32 0, metadata !63} ; [ DW_TAG_arg_variable ] [value] [line 5]
    183 !67 = metadata !{i32 5, i32 0, metadata !40, metadata !63}
    184 !68 = metadata !{i32 5, i32 0, metadata !62, metadata !63}
    185 !69 = metadata !{i32 20, i32 0, metadata !70, null}
    186 !70 = metadata !{i32 786443, metadata !1, metadata !24, i32 20, i32 0, i32 0, i32 2} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/dbg-changes-codegen-branch-folding.cpp]
    187 !71 = metadata !{i32 786689, metadata !35, metadata !"this", null, i32 16777216, metadata !38, i32 1088, metadata !72} ; [ DW_TAG_arg_variable ] [this] [line 0]
    188 !72 = metadata !{i32 21, i32 0, metadata !70, null}
    189 !73 = metadata !{i32 0, i32 0, metadata !35, metadata !72}
    190 !74 = metadata !{i8* getelementptr inbounds ([2 x i8]* @.str1, i64 0, i64 0)}
    191 !75 = metadata !{i32 786689, metadata !35, metadata !"value", metadata !25, i32 33554438, metadata !15, i32 0, metadata !72} ; [ DW_TAG_arg_variable ] [value] [line 6]
    192 !76 = metadata !{i32 6, i32 0, metadata !35, metadata !72}
    193 !77 = metadata !{i32 786689, metadata !35, metadata !"this", null, i32 16777216, metadata !38, i32 1088, metadata !78} ; [ DW_TAG_arg_variable ] [this] [line 0]
    194 !78 = metadata !{i32 23, i32 0, metadata !70, null}
    195 !79 = metadata !{i32 0, i32 0, metadata !35, metadata !78}
    196 !80 = metadata !{i8* getelementptr inbounds ([2 x i8]* @.str2, i64 0, i64 0)}
    197 !81 = metadata !{i32 786689, metadata !35, metadata !"value", metadata !25, i32 33554438, metadata !15, i32 0, metadata !78} ; [ DW_TAG_arg_variable ] [value] [line 6]
    198 !82 = metadata !{i32 6, i32 0, metadata !35, metadata !78}
    199 !83 = metadata !{i32 786689, metadata !35, metadata !"this", null, i32 16777216, metadata !38, i32 1088, metadata !84} ; [ DW_TAG_arg_variable ] [this] [line 0]
    200 !84 = metadata !{i32 24, i32 0, metadata !24, null}
    201 !85 = metadata !{i32 0, i32 0, metadata !35, metadata !84}
    202 !86 = metadata !{i32 786689, metadata !35, metadata !"value", metadata !25, i32 33554438, metadata !15, i32 0, metadata !84} ; [ DW_TAG_arg_variable ] [value] [line 6]
    203 !87 = metadata !{i32 6, i32 0, metadata !35, metadata !84}
    204 !88 = metadata !{i32 25, i32 0, metadata !24, null}
    205