1; RUN: opt < %s -gvn -o /dev/null  -pass-remarks-output=%t -S
2; RUN: cat %t | FileCheck %s
3
4; CHECK:      --- !Missed
5; CHECK-NEXT: Pass:            gvn
6; CHECK-NEXT: Name:            LoadClobbered
7; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 2, Column: 2 }
8; CHECK-NEXT: Function:        multipleUsers
9; CHECK-NEXT: Args:
10; CHECK-NEXT:   - String:          'load of type '
11; CHECK-NEXT:   - Type:            i32
12; CHECK-NEXT:   - String:          ' not eliminated'
13; CHECK-NEXT:   - String:          ' in favor of '
14; CHECK-NEXT:   - OtherAccess:     store
15; CHECK-NEXT:   - String:          ' because it is clobbered by '
16; CHECK-NEXT:   - ClobberedBy:     call
17; CHECK-NEXT:     DebugLoc: { File: '/tmp/s.c', Line: 1, Column: 1 }
18; CHECK-NEXT: ...
19; CHECK:      --- !Missed
20; CHECK-NEXT: Pass:            gvn
21; CHECK-NEXT: Name:            LoadClobbered
22; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 4, Column: 4 }
23; CHECK-NEXT: Function:        multipleUsers
24; CHECK-NEXT: Args:
25; CHECK-NEXT:   - String:          'load of type '
26; CHECK-NEXT:   - Type:            i32
27; CHECK-NEXT:   - String:          ' not eliminated'
28; CHECK-NEXT:   - String:          ' in favor of '
29; CHECK-NEXT:   - OtherAccess:     load
30; CHECK-NEXT:     DebugLoc: { File: '/tmp/s.c', Line: 2, Column: 2 }
31; CHECK-NEXT:   - String:          ' because it is clobbered by '
32; CHECK-NEXT:   - ClobberedBy:     call
33; CHECK-NEXT:     DebugLoc: { File: '/tmp/s.c', Line: 3, Column: 3 }
34; CHECK-NEXT: ...
35
36; ModuleID = 'bugpoint-reduced-simplified.bc'
37source_filename = "gvn-test.c"
38target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
39target triple = "x86_64-unknown-linux-gnu"
40
41; Tests that a last clobbering use can be determined even in the presence of
42; multiple users, given that one of them lies on a path between every other
43; potentially clobbering use and the load.
44
45define dso_local void @multipleUsers(i32* %a, i32 %b) local_unnamed_addr #0 {
46entry:
47  store i32 %b, i32* %a, align 4
48  tail call void @clobberingFunc() #1, !dbg !10
49  %0 = load i32, i32* %a, align 4, !dbg !11
50  tail call void @clobberingFunc() #1, !dbg !12
51  %1 = load i32, i32* %a, align 4, !dbg !13
52  %add2 = add nsw i32 %1, %0
53  ret void
54}
55
56; CHECK:      --- !Missed
57; CHECK-NEXT: Pass:            gvn
58; CHECK-NEXT: Name:            LoadClobbered
59; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 2, Column: 2 }
60; CHECK-NEXT: Function:        multipleUsers2
61; CHECK-NEXT: Args:
62; CHECK-NEXT:   - String:          'load of type '
63; CHECK-NEXT:   - Type:            i32
64; CHECK-NEXT:   - String:          ' not eliminated'
65; CHECK-NEXT:   - String:          ' in favor of '
66; CHECK-NEXT:   - OtherAccess:     store
67; CHECK-NEXT:   - String:          ' because it is clobbered by '
68; CHECK-NEXT:   - ClobberedBy:     call
69; CHECK-NEXT:     DebugLoc: { File: '/tmp/s.c', Line: 1, Column: 1 }
70; CHECK-NEXT: ...
71; CHECK:      --- !Missed
72; CHECK-NEXT: Pass:            gvn
73; CHECK-NEXT: Name:            LoadClobbered
74; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 4, Column: 4 }
75; CHECK-NEXT: Function:        multipleUsers2
76; CHECK-NEXT: Args:
77; CHECK-NEXT:   - String:          'load of type '
78; CHECK-NEXT:   - Type:            i32
79; CHECK-NEXT:   - String:          ' not eliminated'
80; CHECK-NEXT:   - String:          ' in favor of '
81; CHECK-NEXT:   - OtherAccess:     load
82; CHECK-NEXT:     DebugLoc: { File: '/tmp/s.c', Line: 2, Column: 2 }
83; CHECK-NEXT:   - String:          ' because it is clobbered by '
84; CHECK-NEXT:   - ClobberedBy:     call
85; CHECK-NEXT:     DebugLoc: { File: '/tmp/s.c', Line: 3, Column: 3 }
86; CHECK-NEXT: ...
87
88; Ignore uses in other functions
89
90define dso_local void @multipleUsers2(i32 %b) local_unnamed_addr #0 {
91entry:
92  store i32 %b, i32* @g, align 4
93  tail call void @clobberingFunc() #1, !dbg !15
94  %0 = load i32, i32* @g, align 4, !dbg !16
95  tail call void @clobberingFunc() #1, !dbg !17
96  %1 = load i32, i32* @g, align 4, !dbg !18
97  %add3 = add nsw i32 %1, %0
98  ret void
99}
100
101declare dso_local void @clobberingFunc() local_unnamed_addr #0
102
103@g = external global i32
104
105define dso_local void @globalUser(i32 %b) local_unnamed_addr #0 {
106entry:
107  store i32 %b, i32* @g, align 4
108  ret void
109}
110
111
112attributes #0 = { "use-soft-float"="false" }
113attributes #1 = { nounwind }
114
115!llvm.dbg.cu = !{!1}
116!llvm.module.flags = !{!4, !5, !6}
117!llvm.ident = !{!0}
118
119!0 = !{!"clang version 10.0.0 (git@github.com:llvm/llvm-project.git a2f6ae9abffcba260c22bb235879f0576bf3b783)"}
120!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !3)
121!2 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")
122!3 = !{}
123!4 = !{i32 2, !"Dwarf Version", i32 4}
124!5 = !{i32 2, !"Debug Info Version", i32 3}
125!6 = !{i32 1, !"PIC Level", i32 2}
126!8 = distinct !DISubprogram(name: "multipleUsers", scope: !2, file: !2, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !1, retainedNodes: !3)
127!9 = !DISubroutineType(types: !3)
128!10 = !DILocation(line: 1, column: 1, scope: !8)
129!11 = !DILocation(line: 2, column: 2, scope: !8)
130!12 = !DILocation(line: 3, column: 3, scope: !8)
131!13 = !DILocation(line: 4, column: 4, scope: !8)
132!14 = distinct !DISubprogram(name: "multipleUsers2", scope: !2, file: !2, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !1, retainedNodes: !3)
133!15 = !DILocation(line: 1, column: 1, scope: !14)
134!16 = !DILocation(line: 2, column: 2, scope: !14)
135!17 = !DILocation(line: 3, column: 3, scope: !14)
136!18 = !DILocation(line: 4, column: 4, scope: !14)
137