1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=newgvn -S < %s | FileCheck %s
4 ; Check that the redundant load from %if.then is removed.
5 ; Also, check that the debug location associated to load %0 still refers to
6 ; line 3 and not line 6.
8 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
11 define i32 @test_redundant_load(i32 %X, ptr %Y) !dbg !6 {
12 ; CHECK-LABEL: define i32 @test_redundant_load(
13 ; CHECK-SAME: i32 [[X:%.*]], ptr [[Y:%.*]]) !dbg [[DBG6:![0-9]+]] {
15 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !dbg [[DBG8:![0-9]+]]
16 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X]], -1, !dbg [[DBG9:![0-9]+]]
17 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]], !dbg [[DBG9]]
19 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], [[TMP0]], !dbg [[DBG10:![0-9]+]]
20 ; CHECK-NEXT: call void @foo(), !dbg [[DBG11:![0-9]+]]
21 ; CHECK-NEXT: br label [[IF_END]], !dbg [[DBG12:![0-9]+]]
23 ; CHECK-NEXT: [[RESULT_0:%.*]] = phi i32 [ [[ADD]], [[IF_THEN]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
24 ; CHECK-NEXT: ret i32 [[RESULT_0]], !dbg [[DBG13:![0-9]+]]
27 %0 = load i32, ptr %Y, align 4, !dbg !8
28 %cmp = icmp sgt i32 %X, -1, !dbg !9
29 br i1 %cmp, label %if.then, label %if.end, !dbg !9
31 if.then: ; preds = %entry
32 %1 = load i32, ptr %Y, align 4, !dbg !10
33 %add = add nsw i32 %0, %1, !dbg !10
34 call void @foo(), !dbg !11
35 br label %if.end, !dbg !12
37 if.end: ; preds = %if.then, %entry
38 %Result.0 = phi i32 [ %add, %if.then ], [ %0, %entry ]
39 ret i32 %Result.0, !dbg !13
45 !llvm.module.flags = !{!3, !4, !5}
47 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
48 !1 = !DIFile(filename: "test.cpp", directory: "")
50 !3 = !{i32 2, !"Dwarf Version", i32 4}
51 !4 = !{i32 2, !"Debug Info Version", i32 3}
52 !5 = !{i32 1, !"PIC Level", i32 2}
53 !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)
54 !7 = !DISubroutineType(types: !2)
55 !8 = !DILocation(line: 3, scope: !6)
56 !9 = !DILocation(line: 5, scope: !6)
57 !10 = !DILocation(line: 6, scope: !6)
58 !11 = !DILocation(line: 7, scope: !6)
59 !12 = !DILocation(line: 8, scope: !6)
60 !13 = !DILocation(line: 10, scope: !6)
62 ; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: [[META2:![0-9]+]])
63 ; CHECK: [[META1]] = !DIFile(filename: "test.cpp", directory: "")
64 ; CHECK: [[META2]] = !{}
65 ; CHECK: [[DBG6]] = distinct !DISubprogram(name: "test_redundant_load", scope: [[META1]], file: [[META1]], line: 2, type: [[META7:![0-9]+]], scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META2]])
66 ; CHECK: [[META7]] = !DISubroutineType(types: [[META2]])
67 ; CHECK: [[DBG8]] = !DILocation(line: 3, scope: [[DBG6]])
68 ; CHECK: [[DBG9]] = !DILocation(line: 5, scope: [[DBG6]])
69 ; CHECK: [[DBG10]] = !DILocation(line: 6, scope: [[DBG6]])
70 ; CHECK: [[DBG11]] = !DILocation(line: 7, scope: [[DBG6]])
71 ; CHECK: [[DBG12]] = !DILocation(line: 8, scope: [[DBG6]])
72 ; CHECK: [[DBG13]] = !DILocation(line: 10, scope: [[DBG6]])