1; XFAIL: *
2; RUN: opt < %s -newgvn -o /dev/null  -pass-remarks-output=%t -S -pass-remarks=gvn \
3; RUN:     2>&1 | FileCheck %s
4; RUN: cat %t | FileCheck -check-prefix=YAML %s
5; RUN: opt < %s -passes=newgvn -o /dev/null  -pass-remarks-output=%t -S -pass-remarks=gvn \
6; RUN:     2>&1 | FileCheck %s
7; RUN: cat %t | FileCheck -check-prefix=YAML %s
8
9
10; CHECK:      remark: <unknown>:0:0: load of type i32 eliminated{{$}}
11; CHECK-NEXT: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
12; CHECK-NEXT: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
13; CHECK-NOT:  remark:
14
15; YAML:      --- !Passed
16; YAML-NEXT: Pass:            gvn
17; YAML-NEXT: Name:            LoadElim
18; YAML-NEXT: Function:        arg
19; YAML-NEXT: Args:
20; YAML-NEXT:   - String:          'load of type '
21; YAML-NEXT:   - Type:            i32
22; YAML-NEXT:   - String:          ' eliminated'
23; YAML-NEXT:   - String:          ' in favor of '
24; YAML-NEXT:   - InfavorOfValue:  i
25; YAML-NEXT: ...
26; YAML-NEXT: --- !Passed
27; YAML-NEXT: Pass:            gvn
28; YAML-NEXT: Name:            LoadElim
29; YAML-NEXT: Function:        const
30; YAML-NEXT: Args:
31; YAML-NEXT:   - String:          'load of type '
32; YAML-NEXT:   - Type:            i32
33; YAML-NEXT:   - String:          ' eliminated'
34; YAML-NEXT:   - String:          ' in favor of '
35; YAML-NEXT:   - InfavorOfValue:  '4'
36; YAML-NEXT: ...
37; YAML-NEXT: --- !Passed
38; YAML-NEXT: Pass:            gvn
39; YAML-NEXT: Name:            LoadElim
40; YAML-NEXT: Function:        inst
41; YAML-NEXT: Args:
42; YAML-NEXT:   - String:          'load of type '
43; YAML-NEXT:   - Type:            i32
44; YAML-NEXT:   - String:          ' eliminated'
45; YAML-NEXT:   - String:          ' in favor of '
46; YAML-NEXT:   - InfavorOfValue:  load
47; YAML-NEXT: ...
48; YAML-NEXT: --- !Missed
49; YAML-NEXT: Pass:            gvn
50; YAML-NEXT: Name:            LoadClobbered
51; YAML-NEXT: DebugLoc:        { File: /tmp/s.c, Line: 3, Column: 3 }
52; YAML-NEXT: Function:        may_alias
53; YAML-NEXT: Args:
54; YAML-NEXT:   - String:          'load of type '
55; YAML-NEXT:   - Type:            i32
56; YAML-NEXT:   - String:          ' not eliminated'
57; YAML-NEXT:   - String:          ' in favor of '
58; YAML-NEXT:   - OtherAccess:     load
59; YAML-NEXT:     DebugLoc:        { File: /tmp/s.c, Line: 1, Column: 13 }
60; YAML-NEXT:   - String:          ' because it is clobbered by '
61; YAML-NEXT:   - ClobberedBy:     store
62; YAML-NEXT:     DebugLoc:        { File: /tmp/s.c, Line: 2, Column: 10 }
63; YAML-NEXT: ...
64
65define i32 @arg(i32* %p, i32 %i) {
66entry:
67  store i32 %i, i32* %p
68  %load = load i32, i32* %p
69  ret i32 %load
70}
71
72define i32 @const(i32* %p) {
73entry:
74  store i32 4, i32* %p
75  %load = load i32, i32* %p
76  ret i32 %load
77}
78
79define i32 @inst(i32* %p) {
80entry:
81  %load1 = load i32, i32* %p
82  %load = load i32, i32* %p
83  %add = add i32 %load1, %load
84  ret i32 %add
85}
86
87define i32 @may_alias(i32* %p, i32* %r) !dbg !7 {
88entry:
89  %load1 = load i32, i32* %p, !tbaa !13, !dbg !9
90  store i32 4, i32* %r, !tbaa !13, !dbg !10
91  %load = load i32, i32* %p, !tbaa !13, !dbg !11
92  %add = add i32 %load1, %load
93  ret i32 %add
94}
95!llvm.dbg.cu = !{!0}
96!llvm.module.flags = !{!3, !4, !5}
97!llvm.ident = !{!6}
98
99!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
100!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")
101!2 = !{}
102!3 = !{i32 2, !"Dwarf Version", i32 4}
103!4 = !{i32 2, !"Debug Info Version", i32 3}
104!5 = !{i32 1, !"PIC Level", i32 2}
105!6 = !{!"clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)"}
106!7 = distinct !DISubprogram(name: "may_alias", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !2)
107!8 = !DISubroutineType(types: !2)
108!9 = !DILocation(line: 1, column: 13, scope: !7)
109!10 = !DILocation(line: 2, column: 10, scope: !7)
110!11 = !DILocation(line: 3, column: 3, scope: !7)
111
112!12 = !{ !"tbaa root" }
113!13 = !{ !"int", !12 }
114