Home | History | Annotate | Download | only in GVN
      1 ; RUN: opt -gvn -S < %s | FileCheck %s
      2 
      3 ; Check that the redundant load from %if.then is removed.
      4 ; Also, check that the debug location associated to load %0 still refers to
      5 ; line 3 and not line 6.
      6 
      7 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
      8 
      9 ; CHECK: @test_redundant_load(
     10 ; CHECK-LABEL: entry:
     11 ; CHECK-NEXT: load i32, i32* %Y, align 4, !dbg ![[LOC:[0-9]+]]
     12 ; CHECK-LABEL: if.then:
     13 ; CHECK-NOT: load
     14 ; CHECK-LABEL: if.end:
     15 ; CHECK: ![[LOC]] = !DILocation(line: 3, scope: !{{.*}})
     16 
     17 define i32 @test_redundant_load(i32 %X, i32* %Y) !dbg !6 {
     18 entry:
     19   %0 = load i32, i32* %Y, align 4, !dbg !8
     20   %cmp = icmp sgt i32 %X, -1, !dbg !9
     21   br i1 %cmp, label %if.then, label %if.end, !dbg !9
     22 
     23 if.then:                                          ; preds = %entry
     24   %1 = load i32, i32* %Y, align 4, !dbg !10
     25   %add = add nsw i32 %0, %1, !dbg !10
     26   call void @foo(), !dbg !11
     27   br label %if.end, !dbg !12
     28 
     29 if.end:                                           ; preds = %if.then, %entry
     30   %Result.0 = phi i32 [ %add, %if.then ], [ %0, %entry ]
     31   ret i32 %Result.0, !dbg !13
     32 }
     33 
     34 declare void @foo()
     35 
     36 !llvm.dbg.cu = !{!0}
     37 !llvm.module.flags = !{!3, !4, !5}
     38 
     39 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
     40 !1 = !DIFile(filename: "test.cpp", directory: "")
     41 !2 = !{}
     42 !3 = !{i32 2, !"Dwarf Version", i32 4}
     43 !4 = !{i32 2, !"Debug Info Version", i32 3}
     44 !5 = !{i32 1, !"PIC Level", i32 2}
     45 !6 = distinct !DISubprogram(name: "test_redundant_load", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
     46 !7 = !DISubroutineType(types: !2)
     47 !8 = !DILocation(line: 3, scope: !6)
     48 !9 = !DILocation(line: 5, scope: !6)
     49 !10 = !DILocation(line: 6, scope: !6)
     50 !11 = !DILocation(line: 7, scope: !6)
     51 !12 = !DILocation(line: 8, scope: !6)
     52 !13 = !DILocation(line: 10, scope: !6)
     53