Taints the non-acquire RMW's store address with the load part
[oota-llvm.git] / test / Transforms / GVN / load-pre-nonlocal.ll
1 ; RUN: opt -S -o - -basicaa -domtree -gvn %s | FileCheck %s
2
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4
5 %struct.S1 = type { i32, i32 }
6
7 @a2 = common global i32* null, align 8
8 @a = common global i32* null, align 8
9 @s1 = common global %struct.S1 zeroinitializer, align 8
10
11 ; Check that GVN doesn't determine %2 is partially redundant.
12
13 ; CHECK-LABEL: define i32 @volatile_load
14 ; CHECK: for.body:
15 ; CHECK: %2 = load i32, i32*
16 ; CHECK: %3 = load volatile i32, i32*
17 ; CHECK: for.cond.for.end_crit_edge:
18
19 define i32 @volatile_load(i32 %n) {
20 entry:
21   %cmp6 = icmp sgt i32 %n, 0
22   br i1 %cmp6, label %for.body.lr.ph, label %for.end
23
24 for.body.lr.ph:
25   %0 = load i32*, i32** @a2, align 8, !tbaa !1
26   %1 = load i32*, i32** @a, align 8, !tbaa !1
27   br label %for.body
28
29 for.body:
30   %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
31   %s.09 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ]
32   %p.08 = phi i32* [ %0, %for.body.lr.ph ], [ %incdec.ptr, %for.body ]
33   %2 = load i32, i32* %p.08, align 4, !tbaa !5
34   %arrayidx = getelementptr inbounds i32, i32* %1, i64 %indvars.iv
35   store i32 %2, i32* %arrayidx, align 4, !tbaa !5
36   %3 = load volatile i32, i32* %p.08, align 4, !tbaa !5
37   %add = add nsw i32 %3, %s.09
38   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
39   %incdec.ptr = getelementptr inbounds i32, i32* %p.08, i64 1
40   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
41   %exitcond = icmp ne i32 %lftr.wideiv, %n
42   br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge
43
44 for.cond.for.end_crit_edge:
45   %add.lcssa = phi i32 [ %add, %for.body ]
46   br label %for.end
47
48 for.end:
49   %s.0.lcssa = phi i32 [ %add.lcssa, %for.cond.for.end_crit_edge ], [ 0, %entry ]
50   ret i32 %s.0.lcssa
51 }
52
53 ; %1 is partially redundant if %0 can be widened to a 64-bit load.
54
55 ; CHECK-LABEL: define i32 @overaligned_load
56 ; CHECK: if.then:
57 ; CHECK:   %0 = load i64
58 ; CHECK:   [[LSHR:%[0-9]+]] = lshr i64 %0, 32, !dbg [[LSHR_LOC:![0-9]+]]
59 ; CHECK:   trunc i64 [[LSHR]] to i32
60 ; CHECK: if.end:
61 ; CHECK-NOT: %1 = load i32, i32*
62 ; CHECK: [[LSHR_LOC]] = !DILocation(line: 101, column: 1, scope: !{{.*}})
63
64 define i32 @overaligned_load(i32 %a, i32* nocapture %b) !dbg !13 {
65 entry:
66   %cmp = icmp sgt i32 %a, 0, !dbg !14
67   br i1 %cmp, label %if.then, label %if.else, !dbg !14
68
69 if.then:
70   %0 = load i32, i32* getelementptr inbounds (%struct.S1, %struct.S1* @s1, i64 0, i32 0), align 8, !tbaa !5, !dbg !15
71   br label %if.end, !dbg !15
72
73 if.else:
74   %arrayidx = getelementptr inbounds i32, i32* %b, i64 2, !dbg !16
75   store i32 10, i32* %arrayidx, align 4, !tbaa !5, !dbg !16
76   br label %if.end, !dbg !16
77
78 if.end:
79   %i.0 = phi i32 [ %0, %if.then ], [ 0, %if.else ]
80   %p.0 = phi i32* [ getelementptr inbounds (%struct.S1, %struct.S1* @s1, i64 0, i32 0), %if.then ], [ %b, %if.else ]
81   %add.ptr = getelementptr inbounds i32, i32* %p.0, i64 1, !dbg !17
82   %1 = load i32, i32* %add.ptr, align 4, !tbaa !5, !dbg !17
83   %add1 = add nsw i32 %1, %i.0, !dbg !17
84   ret i32 %add1, !dbg !17
85 }
86
87 !1 = !{!2, !2, i64 0}
88 !2 = !{!"any pointer", !3, i64 0}
89 !3 = !{!"omnipotent char", !4, i64 0}
90 !4 = !{!"Simple C/C++ TBAA"}
91 !5 = !{!6, !6, i64 0}
92 !6 = !{!"int", !3, i64 0}
93
94 !llvm.module.flags = !{!7, !8, !9}
95 !7 = !{i32 2, !"Dwarf Version", i32 4}
96 !8 = !{i32 2, !"Debug Info Version", i32 3}
97 !9 = !{i32 1, !"PIC Level", i32 2}
98
99 !10 = !{}
100 !11 = !DISubroutineType(types: !10)
101 !12 = !DIFile(filename: "test.cpp", directory: "/tmp")
102 !13 = distinct !DISubprogram(name: "test", scope: !12, file: !12, line: 99, type: !11, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, variables: !10)
103 !14 = !DILocation(line: 100, column: 1, scope: !13)
104 !15 = !DILocation(line: 101, column: 1, scope: !13)
105 !16 = !DILocation(line: 102, column: 1, scope: !13)
106 !17 = !DILocation(line: 103, column: 1, scope: !13)
107