1; RUN: opt -S -passes=globalopt < %s | FileCheck %s 2 3;; Generated at -g from: 4;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 5;;subroutine sub(inode,node) 6;; implicit none 7;; integer nodea,nodeb,jmax,inode,node 8;; save nodea,nodeb,jmax 9;; if(inode.eq.1) then 10;; nodea=node 11;; nodeb=node 12;; jmax=0 13;; else 14;; jmax=node+1+nodea+nodeb+jmax 15;; return 16;; endif 17;;end 18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 19 20%struct.BSS1 = type <{ [12 x i8] }> 21 22;CHECK: @.BSS1.0 = internal unnamed_addr global i32 0, align 32, !dbg ![[GVE1:.*]] 23;CHECK: @.BSS1.1 = internal unnamed_addr global i32 0, align 4, !dbg ![[GVE2:.*]], !dbg ![[GVE4:.*]] 24;CHECK: @.BSS1.2 = internal unnamed_addr global i32 0, align 8, !dbg ![[GVE3:.*]] 25 26@.BSS1 = internal global %struct.BSS1 zeroinitializer, align 32, !dbg !0, !dbg !7, !dbg !10, !dbg !27, !dbg !29 27@.C330_sub_ = internal constant i32 0 28@.C332_sub_ = internal constant i32 1 29 30define void @sub_(ptr noalias %inode, ptr noalias %node) !dbg !2 { 31L.entry: 32 call void @llvm.dbg.declare(metadata ptr %inode, metadata !16, metadata !DIExpression()), !dbg !17 33 call void @llvm.dbg.declare(metadata ptr %node, metadata !18, metadata !DIExpression()), !dbg !17 34 br label %L.LB1_360 35 36L.LB1_360: ; preds = %L.entry 37 %0 = load i32, ptr %inode, align 4, !dbg !19 38 %1 = icmp ne i32 %0, 1, !dbg !19 39 br i1 %1, label %L.LB1_356, label %L.LB1_370, !dbg !19 40 41L.LB1_370: ; preds = %L.LB1_360 42 %2 = load i32, ptr %node, align 4, !dbg !20 43 store i32 %2, ptr @.BSS1, align 4, !dbg !20 44 %3 = load i32, ptr %node, align 4, !dbg !21 45 %4 = getelementptr i8, ptr @.BSS1, i64 4, !dbg !21 46 store i32 %3, ptr %4, align 4, !dbg !21 47 %5 = getelementptr i8, ptr @.BSS1, i64 8, !dbg !22 48 store i32 0, ptr %5, align 4, !dbg !22 49 br label %L.LB1_357, !dbg !23 50 51L.LB1_356: ; preds = %L.LB1_360 52 %6 = load i32, ptr %node, align 4, !dbg !24 53 %7 = add nsw i32 %6, 1, !dbg !24 54 %8 = load i32, ptr @.BSS1, align 4, !dbg !24 55 %9 = add nsw i32 %7, %8, !dbg !24 56 %10 = getelementptr i8, ptr @.BSS1, i64 4, !dbg !24 57 %11 = load i32, ptr %10, align 4, !dbg !24 58 %12 = add nsw i32 %9, %11, !dbg !24 59 %13 = getelementptr i8, ptr @.BSS1, i64 8, !dbg !24 60 %14 = load i32, ptr %13, align 4, !dbg !24 61 %15 = add nsw i32 %12, %14, !dbg !24 62 %16 = getelementptr i8, ptr @.BSS1, i64 8, !dbg !24 63 store i32 %15, ptr %16, align 4, !dbg !24 64 br label %L.LB1_354, !dbg !25 65 66L.LB1_357: ; preds = %L.LB1_370 67 br label %L.LB1_354 68 69L.LB1_354: ; preds = %L.LB1_357, %L.LB1_356 70 ret void, !dbg !26 71} 72 73; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 74declare void @llvm.dbg.declare(metadata, metadata, metadata) 75 76!llvm.module.flags = !{!14, !15} 77!llvm.dbg.cu = !{!4} 78 79; CHECK-DAG: ![[GVE1]] = !DIGlobalVariableExpression(var: ![[GV1:.*]], expr: !DIExpression()) 80; CHECK-DAG: ![[GV1]] = distinct !DIGlobalVariable(name: "nodea" 81; CHECK-DAG: ![[GVE2]] = !DIGlobalVariableExpression(var: ![[GV2:.*]], expr: !DIExpression()) 82; CHECK-DAG: ![[GV2]] = distinct !DIGlobalVariable(name: "nodeb" 83; CHECK-DAG: ![[GVE3]] = !DIGlobalVariableExpression(var: ![[GV3:.*]], expr: !DIExpression()) 84; CHECK-DAG: ![[GV3]] = distinct !DIGlobalVariable(name: "jmax" 85; CHECK-DAG: ![[GVE4]] = !DIGlobalVariableExpression(var: ![[GV4:.*]], expr: !DIExpression(DW_OP_plus_uconst, 2)) 86; CHECK-DAG: ![[GV4]] = distinct !DIGlobalVariable(name: "ivar2" 87 88;; This does not make sense should be removed. 89; CHECK-NOT: !DIGlobalVariable(name: "doesnotexist" 90 91!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 92!1 = distinct !DIGlobalVariable(name: "nodea", scope: !2, file: !3, line: 3, type: !9, isLocal: true, isDefinition: true) 93!2 = distinct !DISubprogram(name: "sub", scope: !4, file: !3, line: 1, type: !12, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition, unit: !4) 94!3 = !DIFile(filename: "global-sra-struct-fit-segment.f90", directory: "/tmp") 95!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g -O0 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5, nameTableKind: None) 96!5 = !{} 97!6 = !{!0, !7, !10, !29} 98!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression(DW_OP_plus_uconst, 4)) 99!8 = distinct !DIGlobalVariable(name: "nodeb", scope: !2, file: !3, line: 3, type: !9, isLocal: true, isDefinition: true) 100!9 = !DIBasicType(name: "integer", size: 32, align: 32, encoding: DW_ATE_signed) 101!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression(DW_OP_plus_uconst, 8)) 102!11 = distinct !DIGlobalVariable(name: "jmax", scope: !2, file: !3, line: 3, type: !9, isLocal: true, isDefinition: true) 103!12 = !DISubroutineType(types: !13) 104!13 = !{null, !9, !9} 105!14 = !{i32 2, !"Dwarf Version", i32 4} 106!15 = !{i32 2, !"Debug Info Version", i32 3} 107!16 = !DILocalVariable(name: "inode", arg: 1, scope: !2, file: !3, line: 1, type: !9) 108!17 = !DILocation(line: 0, scope: !2) 109!18 = !DILocalVariable(name: "node", arg: 2, scope: !2, file: !3, line: 1, type: !9) 110!19 = !DILocation(line: 5, column: 1, scope: !2) 111!20 = !DILocation(line: 6, column: 1, scope: !2) 112!21 = !DILocation(line: 7, column: 1, scope: !2) 113!22 = !DILocation(line: 8, column: 1, scope: !2) 114!23 = !DILocation(line: 9, column: 1, scope: !2) 115!24 = !DILocation(line: 10, column: 1, scope: !2) 116!25 = !DILocation(line: 11, column: 1, scope: !2) 117!26 = !DILocation(line: 13, column: 1, scope: !2) 118!27 = !DIGlobalVariableExpression(var: !28, expr: !DIExpression(DW_OP_constu, 4, DW_OP_minus)) 119!28 = distinct !DIGlobalVariable(name: "doesnotexist", scope: !2, file: !3, line: 3, type: !9, isLocal: true, isDefinition: true) 120!29 = !DIGlobalVariableExpression(var: !30, expr: !DIExpression(DW_OP_plus_uconst, 6)) 121!30 = distinct !DIGlobalVariable(name: "ivar2", scope: !2, file: !3, line: 3, type: !31, isLocal: true, isDefinition: true) 122!31 = !DIBasicType(name: "integer*2", size: 16, align: 16, encoding: DW_ATE_signed) 123