xref: /aosp_15_r20/external/llvm/test/Transforms/GVN/volatile-nonvolatile.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -tbaa -gvn -S < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker%struct.t = type { i32* }
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; The loaded address and the location of the address itself are not aliased,
6*9880d681SAndroid Build Coastguard Worker; so the second reload is not necessary. Check that it can be eliminated.
7*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1
8*9880d681SAndroid Build Coastguard Worker; CHECK: load
9*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load
10*9880d681SAndroid Build Coastguard Workerdefine void @test1(%struct.t* nocapture readonly %p, i32 %v) #0 {
11*9880d681SAndroid Build Coastguard Workerentry:
12*9880d681SAndroid Build Coastguard Worker  %m = getelementptr inbounds %struct.t, %struct.t* %p, i32 0, i32 0
13*9880d681SAndroid Build Coastguard Worker  %0 = load i32*, i32** %m, align 4, !tbaa !1
14*9880d681SAndroid Build Coastguard Worker  store volatile i32 %v, i32* %0, align 4, !tbaa !6
15*9880d681SAndroid Build Coastguard Worker  %1 = load i32*, i32** %m, align 4, !tbaa !1
16*9880d681SAndroid Build Coastguard Worker  store volatile i32 %v, i32* %1, align 4, !tbaa !6
17*9880d681SAndroid Build Coastguard Worker  ret void
18*9880d681SAndroid Build Coastguard Worker}
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker; The store via the loaded address may overwrite the address itself.
21*9880d681SAndroid Build Coastguard Worker; Make sure that both loads remain.
22*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2
23*9880d681SAndroid Build Coastguard Worker; CHECK: load
24*9880d681SAndroid Build Coastguard Worker; CHECK: store
25*9880d681SAndroid Build Coastguard Worker; CHECK: load
26*9880d681SAndroid Build Coastguard Workerdefine void @test2(%struct.t* nocapture readonly %p, i32 %v) #0 {
27*9880d681SAndroid Build Coastguard Workerentry:
28*9880d681SAndroid Build Coastguard Worker  %m = getelementptr inbounds %struct.t, %struct.t* %p, i32 0, i32 0
29*9880d681SAndroid Build Coastguard Worker  %0 = load i32*, i32** %m, align 4, !tbaa !1
30*9880d681SAndroid Build Coastguard Worker  store volatile i32 %v, i32* %0, align 4, !tbaa !1
31*9880d681SAndroid Build Coastguard Worker  %1 = load i32*, i32** %m, align 4, !tbaa !1
32*9880d681SAndroid Build Coastguard Worker  store volatile i32 %v, i32* %1, align 4, !tbaa !1
33*9880d681SAndroid Build Coastguard Worker  ret void
34*9880d681SAndroid Build Coastguard Worker}
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker; The loads are ordered and non-monotonic. Although they are not aliased to
37*9880d681SAndroid Build Coastguard Worker; the stores, make sure both are preserved.
38*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3
39*9880d681SAndroid Build Coastguard Worker; CHECK: load
40*9880d681SAndroid Build Coastguard Worker; CHECK: store
41*9880d681SAndroid Build Coastguard Worker; CHECK: load
42*9880d681SAndroid Build Coastguard Workerdefine void @test3(%struct.t* nocapture readonly %p, i32 %v) #0 {
43*9880d681SAndroid Build Coastguard Workerentry:
44*9880d681SAndroid Build Coastguard Worker  %m = getelementptr inbounds %struct.t, %struct.t* %p, i32 0, i32 0
45*9880d681SAndroid Build Coastguard Worker  %0 = load atomic i32*, i32** %m acquire, align 4, !tbaa !1
46*9880d681SAndroid Build Coastguard Worker  store volatile i32 %v, i32* %0, align 4, !tbaa !6
47*9880d681SAndroid Build Coastguard Worker  %1 = load atomic i32*, i32** %m acquire, align 4, !tbaa !1
48*9880d681SAndroid Build Coastguard Worker  store volatile i32 %v, i32* %1, align 4, !tbaa !6
49*9880d681SAndroid Build Coastguard Worker  ret void
50*9880d681SAndroid Build Coastguard Worker}
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Workerattributes #0 = { norecurse nounwind }
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker!1 = !{!2, !3, i64 0}
55*9880d681SAndroid Build Coastguard Worker!2 = !{!"", !3, i64 0}
56*9880d681SAndroid Build Coastguard Worker!3 = !{!"any pointer", !4, i64 0}
57*9880d681SAndroid Build Coastguard Worker!4 = !{!"omnipotent char", !5, i64 0}
58*9880d681SAndroid Build Coastguard Worker!5 = !{!"Simple C/C++ TBAA"}
59*9880d681SAndroid Build Coastguard Worker!6 = !{!7, !7, i64 0}
60*9880d681SAndroid Build Coastguard Worker!7 = !{!"int", !4, i64 0}
61*9880d681SAndroid Build Coastguard Worker
62