global-sra-struct.ll 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ; RUN: opt -S -globalopt < %s | FileCheck %s
  2. source_filename = "test.c"
  3. target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  4. target triple = "x86_64-apple-macosx10.12.0"
  5. %struct.mystruct = type { i32, i64 }
  6. ; Generated at -Os from:
  7. ;
  8. ; static struct mystruct {
  9. ; int a;
  10. ; long long int b;
  11. ; } static_struct;
  12. ; void __attribute__((nodebug)) foo(int in) { static_struct.a = in; }
  13. ; void __attribute__((nodebug)) bar(int in) { static_struct.b = in; }
  14. ; int main(int argc, char **argv)
  15. ; {
  16. ; foo(argv[0][1]);
  17. ; bar(argv[0][1]);
  18. ; return static_struct.a + static_struct.b;
  19. ; }
  20. ; CHECK: @static_struct.0 = internal unnamed_addr global i32 0, align 8, !dbg ![[EL0:.*]]
  21. ; CHECK: @static_struct.1 = internal unnamed_addr global i64 0, align 8, !dbg ![[EL1:.*]]
  22. ; CHECK: ![[EL0]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: !DIExpression(DW_OP_LLVM_fragment, 0, 32))
  23. ; CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "static_struct"
  24. ; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: !DIExpression(DW_OP_LLVM_fragment, 64, 64))
  25. @static_struct = internal global %struct.mystruct zeroinitializer, align 8, !dbg !0
  26. ; Function Attrs: nounwind optsize ssp uwtable
  27. define void @foo(i32 %in) #0 {
  28. entry:
  29. store i32 %in, i32* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 0), align 8, !tbaa !17
  30. ret void
  31. }
  32. ; Function Attrs: nounwind optsize ssp uwtable
  33. define void @bar(i32 %in) #0 {
  34. entry:
  35. %conv = sext i32 %in to i64
  36. store i64 %conv, i64* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 1), align 8, !tbaa !23
  37. ret void
  38. }
  39. ; Function Attrs: nounwind optsize ssp uwtable
  40. define i32 @main(i32 %argc, i8** %argv) #0 !dbg !24 {
  41. entry:
  42. call void @llvm.dbg.value(metadata i32 %argc, metadata !31, metadata !33), !dbg !34
  43. call void @llvm.dbg.value(metadata i8** %argv, metadata !32, metadata !33), !dbg !35
  44. %0 = load i8*, i8** %argv, align 8, !dbg !36, !tbaa !37
  45. %arrayidx1 = getelementptr inbounds i8, i8* %0, i64 1, !dbg !36
  46. %1 = load i8, i8* %arrayidx1, align 1, !dbg !36, !tbaa !39
  47. %conv = sext i8 %1 to i32, !dbg !36
  48. call void @foo(i32 %conv) #2, !dbg !40
  49. %2 = load i8*, i8** %argv, align 8, !dbg !41, !tbaa !37
  50. %arrayidx3 = getelementptr inbounds i8, i8* %2, i64 1, !dbg !41
  51. %3 = load i8, i8* %arrayidx3, align 1, !dbg !41, !tbaa !39
  52. %conv4 = sext i8 %3 to i32, !dbg !41
  53. call void @bar(i32 %conv4) #2, !dbg !42
  54. %4 = load i32, i32* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 0), align 8, !dbg !43, !tbaa !17
  55. %conv5 = sext i32 %4 to i64, !dbg !44
  56. %5 = load i64, i64* getelementptr inbounds (%struct.mystruct, %struct.mystruct* @static_struct, i32 0, i32 1), align 8, !dbg !45, !tbaa !23
  57. %add = add nsw i64 %conv5, %5, !dbg !46
  58. %conv6 = trunc i64 %add to i32, !dbg !44
  59. ret i32 %conv6, !dbg !47
  60. }
  61. ; Function Attrs: nounwind readnone speculatable
  62. declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
  63. ; Function Attrs: nounwind readnone speculatable
  64. declare void @llvm.dbg.value(metadata, metadata, metadata) #1
  65. attributes #0 = { nounwind optsize ssp uwtable }
  66. attributes #1 = { nounwind readnone speculatable }
  67. attributes #2 = { optsize }
  68. !llvm.dbg.cu = !{!2}
  69. !llvm.module.flags = !{!12, !13, !14, !15}
  70. !llvm.ident = !{!16}
  71. !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
  72. !1 = distinct !DIGlobalVariable(name: "static_struct", scope: !2, file: !3, line: 4, type: !6, isLocal: true, isDefinition: true)
  73. !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0 (trunk 309852) (llvm/trunk 309850)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
  74. !3 = !DIFile(filename: "test.c", directory: "/")
  75. !4 = !{}
  76. !5 = !{!0}
  77. !6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "mystruct", file: !3, line: 1, size: 128, elements: !7)
  78. !7 = !{!8, !10}
  79. !8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !3, line: 2, baseType: !9, size: 32)
  80. !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  81. !10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !3, line: 3, baseType: !11, size: 64, offset: 64)
  82. !11 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
  83. !12 = !{i32 2, !"Dwarf Version", i32 4}
  84. !13 = !{i32 2, !"Debug Info Version", i32 3}
  85. !14 = !{i32 1, !"wchar_size", i32 4}
  86. !15 = !{i32 7, !"PIC Level", i32 2}
  87. !16 = !{!"clang version 6.0.0 (trunk 309852) (llvm/trunk 309850)"}
  88. !17 = !{!18, !19, i64 0}
  89. !18 = !{!"mystruct", !19, i64 0, !22, i64 8}
  90. !19 = !{!"int", !20, i64 0}
  91. !20 = !{!"omnipotent char", !21, i64 0}
  92. !21 = !{!"Simple C/C++ TBAA"}
  93. !22 = !{!"long long", !20, i64 0}
  94. !23 = !{!18, !22, i64 8}
  95. !24 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 7, type: !25, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !30)
  96. !25 = !DISubroutineType(types: !26)
  97. !26 = !{!9, !9, !27}
  98. !27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !28, size: 64)
  99. !28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 64)
  100. !29 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
  101. !30 = !{!31, !32}
  102. !31 = !DILocalVariable(name: "argc", arg: 1, scope: !24, file: !3, line: 7, type: !9)
  103. !32 = !DILocalVariable(name: "argv", arg: 2, scope: !24, file: !3, line: 7, type: !27)
  104. !33 = !DIExpression()
  105. !34 = !DILocation(line: 7, column: 14, scope: !24)
  106. !35 = !DILocation(line: 7, column: 27, scope: !24)
  107. !36 = !DILocation(line: 9, column: 9, scope: !24)
  108. !37 = !{!38, !38, i64 0}
  109. !38 = !{!"any pointer", !20, i64 0}
  110. !39 = !{!20, !20, i64 0}
  111. !40 = !DILocation(line: 9, column: 5, scope: !24)
  112. !41 = !DILocation(line: 10, column: 9, scope: !24)
  113. !42 = !DILocation(line: 10, column: 5, scope: !24)
  114. !43 = !DILocation(line: 11, column: 26, scope: !24)
  115. !44 = !DILocation(line: 11, column: 12, scope: !24)
  116. !45 = !DILocation(line: 11, column: 44, scope: !24)
  117. !46 = !DILocation(line: 11, column: 28, scope: !24)
  118. !47 = !DILocation(line: 11, column: 5, scope: !24)