1 ; RUN: opt -S -early-cse -earlycse-debug-hash < %s | FileCheck %s
2 ; RUN: opt -S -gvn < %s | FileCheck %s
3 ; RUN: opt -S -newgvn < %s | FileCheck %s
5 ; These tests checks if passes with CSE functionality can do CSE on
6 ; launder.invariant.group, that is prohibited if there is a memory clobber
7 ; between barriers call.
9 ; CHECK-LABEL: define i8 @optimizable()
10 define i8 @optimizable() {
13 store i8 42, i8* %ptr, !invariant.group !0
14 ; CHECK: call i8* @llvm.launder.invariant.group.p0i8
15 %ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
16 ; FIXME: This one could be CSE
17 ; CHECK: call i8* @llvm.launder.invariant.group
18 %ptr3 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
19 ; CHECK: call void @clobber(i8* {{.*}}%ptr)
20 call void @clobber(i8* %ptr)
22 ; CHECK: call void @use(i8* {{.*}}%ptr2)
23 call void @use(i8* %ptr2)
24 ; CHECK: call void @use(i8* {{.*}}%ptr3)
25 call void @use(i8* %ptr3)
26 ; CHECK: load i8, i8* %ptr3, {{.*}}!invariant.group
27 %v = load i8, i8* %ptr3, !invariant.group !0
32 ; CHECK-LABEL: define i8 @unoptimizable()
33 define i8 @unoptimizable() {
36 store i8 42, i8* %ptr, !invariant.group !0
37 ; CHECK: call i8* @llvm.launder.invariant.group.p0i8
38 %ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
39 call void @clobber(i8* %ptr)
40 ; CHECK: call i8* @llvm.launder.invariant.group.p0i8
41 %ptr3 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
42 ; CHECK: call void @clobber(i8* {{.*}}%ptr)
43 call void @clobber(i8* %ptr)
44 ; CHECK: call void @use(i8* {{.*}}%ptr2)
45 call void @use(i8* %ptr2)
46 ; CHECK: call void @use(i8* {{.*}}%ptr3)
47 call void @use(i8* %ptr3)
48 ; CHECK: load i8, i8* %ptr3, {{.*}}!invariant.group
49 %v = load i8, i8* %ptr3, !invariant.group !0
54 ; CHECK-LABEL: define i8 @unoptimizable2()
55 define i8 @unoptimizable2() {
57 store i8 42, i8* %ptr, !invariant.group !0
58 ; CHECK: call i8* @llvm.launder.invariant.group
59 %ptr2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
61 ; CHECK: call i8* @llvm.launder.invariant.group
62 %ptr3 = call i8* @llvm.launder.invariant.group.p0i8(i8* %ptr)
63 ; CHECK: call void @clobber(i8* {{.*}}%ptr)
64 call void @clobber(i8* %ptr)
65 ; CHECK: call void @use(i8* {{.*}}%ptr2)
66 call void @use(i8* %ptr2)
67 ; CHECK: call void @use(i8* {{.*}}%ptr3)
68 call void @use(i8* %ptr3)
69 ; CHECK: load i8, i8* %ptr3, {{.*}}!invariant.group
70 %v = load i8, i8* %ptr3, !invariant.group !0
74 ; This test check if optimizer is not proving equality based on mustalias
75 ; CHECK-LABEL: define void @dontProveEquality(i8* %a)
76 define void @dontProveEquality(i8* %a) {
77 %b = call i8* @llvm.launder.invariant.group.p0i8(i8* %a)
78 %r = icmp eq i8* %b, %a
79 ; CHECK: call void @useBool(i1 %r)
80 call void @useBool(i1 %r)
82 %b2 = call i8* @llvm.strip.invariant.group.p0i8(i8* %a)
83 %r2 = icmp eq i8* %b2, %a
84 ; CHECK: call void @useBool(i1 %r2)
85 call void @useBool(i1 %r2)
90 declare void @use(i8* readonly)
91 declare void @useBool(i1)
93 declare void @clobber(i8*)
94 ; CHECK: Function Attrs: inaccessiblememonly nofree nosync nounwind speculatable willreturn{{$}}
95 ; CHECK-NEXT: declare i8* @llvm.launder.invariant.group.p0i8(i8*)
96 declare i8* @llvm.launder.invariant.group.p0i8(i8*)
98 ; CHECK: Function Attrs: nofree nosync nounwind readnone speculatable willreturn{{$}}
99 ; CHECK-NEXT: declare i8* @llvm.strip.invariant.group.p0i8(i8*)
100 declare i8* @llvm.strip.invariant.group.p0i8(i8*)