Skip to content

Commit a9ced58

Browse files
committed
[GVN] Add MemorySSA checks in tests 1/N
1 parent 53a395f commit a9ced58

File tree

4 files changed

+123
-29
lines changed

4 files changed

+123
-29
lines changed

llvm/test/Transforms/GVN/assume.ll

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes=gvn -verify-analysis-invalidation -S | FileCheck %s
2+
; RUN: opt < %s -passes=gvn -verify-analysis-invalidation -S | FileCheck --check-prefix=CHECK,MDEP %s
3+
; RUN: opt < %s -passes='gvn<memoryssa;no-memdep>' -verify-analysis-invalidation -S | FileCheck --check-prefixes=CHECK,MSSA %s
34

45
declare void @llvm.assume(i1)
56
declare void @use(i1)
@@ -8,6 +9,8 @@ define void @assume_true() {
89
; CHECK-LABEL: @assume_true(
910
; CHECK-NEXT: ret void
1011
;
12+
; CHECK-MSSA-LABEL: @assume_true(
13+
; CHECK-MSSA-NEXT: ret void
1114
call void @llvm.assume(i1 true)
1215
ret void
1316
}
@@ -17,6 +20,9 @@ define void @assume_false() {
1720
; CHECK-NEXT: store i8 poison, ptr null, align 1
1821
; CHECK-NEXT: ret void
1922
;
23+
; CHECK-MSSA-LABEL: @assume_false(
24+
; CHECK-MSSA-NEXT: store i8 poison, ptr null, align 1
25+
; CHECK-MSSA-NEXT: ret void
2026
call void @llvm.assume(i1 false)
2127
ret void
2228
}
@@ -27,6 +33,10 @@ define void @assume_arg(i1 %x) {
2733
; CHECK-NEXT: call void @use(i1 true)
2834
; CHECK-NEXT: ret void
2935
;
36+
; CHECK-MSSA-LABEL: @assume_arg(
37+
; CHECK-MSSA-NEXT: call void @llvm.assume(i1 [[X:%.*]])
38+
; CHECK-MSSA-NEXT: call void @use(i1 true)
39+
; CHECK-MSSA-NEXT: ret void
3040
call void @llvm.assume(i1 %x)
3141
call void @use(i1 %x)
3242
ret void
@@ -39,6 +49,11 @@ define void @assume_not_arg(i1 %x) {
3949
; CHECK-NEXT: call void @use(i1 false)
4050
; CHECK-NEXT: ret void
4151
;
52+
; CHECK-MSSA-LABEL: @assume_not_arg(
53+
; CHECK-MSSA-NEXT: [[XOR:%.*]] = xor i1 [[X:%.*]], true
54+
; CHECK-MSSA-NEXT: call void @llvm.assume(i1 [[XOR]])
55+
; CHECK-MSSA-NEXT: call void @use(i1 false)
56+
; CHECK-MSSA-NEXT: ret void
4257
%xor = xor i1 %x, true
4358
call void @llvm.assume(i1 %xor)
4459
call void @use(i1 %x)
@@ -53,9 +68,18 @@ define void @pr47496(i8 %x) {
5368
; CHECK-NEXT: call void @use(i1 false)
5469
; CHECK-NEXT: ret void
5570
;
71+
; CHECK-MSSA-LABEL: @pr47496(
72+
; CHECK-MSSA-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
73+
; CHECK-MSSA-NEXT: [[XOR:%.*]] = xor i1 [[CMP]], true
74+
; CHECK-MSSA-NEXT: call void @llvm.assume(i1 [[XOR]])
75+
; CHECK-MSSA-NEXT: call void @use(i1 false)
76+
; CHECK-MSSA-NEXT: ret void
5677
%cmp = icmp slt i8 %x, 0
5778
%xor = xor i1 %cmp, true
5879
call void @llvm.assume(i1 %xor)
5980
call void @use(i1 %cmp)
6081
ret void
6182
}
83+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
84+
; MDEP: {{.*}}
85+
; MSSA: {{.*}}

llvm/test/Transforms/GVN/basic.ll

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
; RUN: opt < %s -passes=gvn -S | FileCheck %s
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=gvn -S | FileCheck %s --check-prefixes=CHECK,MDEP
3+
; RUN: opt < %s -passes='gvn<memoryssa;no-memdep>' -S | FileCheck --check-prefixes=CHECK,MSSA %s
24

35
define i32 @main() {
6+
; CHECK-LABEL: define i32 @main() {
7+
; CHECK-NEXT: [[BLOCK1:.*:]]
8+
; CHECK-NEXT: ret i32 0
9+
;
10+
; CHECK-MSSA-LABEL: define i32 @main() {
11+
; CHECK-MSSA-NEXT: [[BLOCK1:.*:]]
12+
; CHECK-MSSA-NEXT: ret i32 0
413
block1:
5-
%z1 = bitcast i32 0 to i32
6-
br label %block2
14+
%z1 = bitcast i32 0 to i32
15+
br label %block2
716
block2:
817
%z2 = bitcast i32 0 to i32
918
ret i32 %z2
1019
}
1120

12-
; CHECK: define i32 @main() {
13-
; CHECK-NEXT: block1:
14-
; CHECK-NEXT: ret i32 0
15-
; CHECK-NEXT: }
21+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
22+
; MDEP: {{.*}}
23+
; MSSA: {{.*}}
Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -S -passes=gvn 2>&1 | FileCheck %s
2+
; RUN: opt < %s -S -passes=gvn 2>&1 | FileCheck %s --check-prefixes=CHECK,MDEP
3+
; RUN: opt < %s -S -passes='gvn<memoryssa;no-memdep>' 2>&1 | FileCheck --check-prefixes=CHECK,MSSA %s
34

45
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
56

@@ -9,11 +10,23 @@ declare noalias ptr @_Znwm(i64)
910
declare void @escape(ptr)
1011

1112
define i8 @test_malloc(ptr %p) {
12-
; CHECK-LABEL: @test_malloc(
13-
; CHECK-NEXT: [[OBJ:%.*]] = call ptr @malloc(i64 16)
14-
; CHECK-NEXT: call void @escape(ptr [[OBJ]])
15-
; CHECK-NEXT: ret i8 0
13+
; MDEP-LABEL: @test_malloc(
14+
; MDEP-NEXT: [[OBJ:%.*]] = call ptr @malloc(i64 16)
15+
; MDEP-NEXT: call void @escape(ptr [[OBJ]])
16+
; MDEP-NEXT: ret i8 0
1617
;
18+
; MSSA-LABEL: @test_malloc(
19+
; MSSA-NEXT: [[V1:%.*]] = load i8, ptr [[P:%.*]], align 1
20+
; MSSA-NEXT: [[OBJ:%.*]] = call ptr @malloc(i64 16)
21+
; MSSA-NEXT: [[V2:%.*]] = load i8, ptr [[P]], align 1
22+
; MSSA-NEXT: [[SUB:%.*]] = sub i8 [[V1]], [[V2]]
23+
; MSSA-NEXT: call void @escape(ptr [[OBJ]])
24+
; MSSA-NEXT: ret i8 [[SUB]]
25+
;
26+
; CHECK-MSSA-LABEL: @test_malloc(
27+
; CHECK-MSSA-NEXT: [[OBJ:%.*]] = call ptr @malloc(i64 16)
28+
; CHECK-MSSA-NEXT: call void @escape(ptr [[OBJ]])
29+
; CHECK-MSSA-NEXT: ret i8 0
1730
%v1 = load i8, ptr %p
1831
%obj = call ptr @malloc(i64 16)
1932
%v2 = load i8, ptr %p
@@ -23,11 +36,23 @@ define i8 @test_malloc(ptr %p) {
2336
}
2437

2538
define i8 @test_calloc(ptr %p) {
26-
; CHECK-LABEL: @test_calloc(
27-
; CHECK-NEXT: [[OBJ:%.*]] = call ptr @calloc(i64 1, i64 16)
28-
; CHECK-NEXT: call void @escape(ptr [[OBJ]])
29-
; CHECK-NEXT: ret i8 0
39+
; MDEP-LABEL: @test_calloc(
40+
; MDEP-NEXT: [[OBJ:%.*]] = call ptr @calloc(i64 1, i64 16)
41+
; MDEP-NEXT: call void @escape(ptr [[OBJ]])
42+
; MDEP-NEXT: ret i8 0
43+
;
44+
; MSSA-LABEL: @test_calloc(
45+
; MSSA-NEXT: [[V1:%.*]] = load i8, ptr [[P:%.*]], align 1
46+
; MSSA-NEXT: [[OBJ:%.*]] = call ptr @calloc(i64 1, i64 16)
47+
; MSSA-NEXT: [[V2:%.*]] = load i8, ptr [[P]], align 1
48+
; MSSA-NEXT: [[SUB:%.*]] = sub i8 [[V1]], [[V2]]
49+
; MSSA-NEXT: call void @escape(ptr [[OBJ]])
50+
; MSSA-NEXT: ret i8 [[SUB]]
3051
;
52+
; CHECK-MSSA-LABEL: @test_calloc(
53+
; CHECK-MSSA-NEXT: [[OBJ:%.*]] = call ptr @calloc(i64 1, i64 16)
54+
; CHECK-MSSA-NEXT: call void @escape(ptr [[OBJ]])
55+
; CHECK-MSSA-NEXT: ret i8 0
3156
%v1 = load i8, ptr %p
3257
%obj = call ptr @calloc(i64 1, i64 16)
3358
%v2 = load i8, ptr %p
@@ -37,11 +62,23 @@ define i8 @test_calloc(ptr %p) {
3762
}
3863

3964
define i8 @test_opnew(ptr %p) {
40-
; CHECK-LABEL: @test_opnew(
41-
; CHECK-NEXT: [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
42-
; CHECK-NEXT: call void @escape(ptr [[OBJ]])
43-
; CHECK-NEXT: ret i8 0
65+
; MDEP-LABEL: @test_opnew(
66+
; MDEP-NEXT: [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
67+
; MDEP-NEXT: call void @escape(ptr [[OBJ]])
68+
; MDEP-NEXT: ret i8 0
69+
;
70+
; MSSA-LABEL: @test_opnew(
71+
; MSSA-NEXT: [[V1:%.*]] = load i8, ptr [[P:%.*]], align 1
72+
; MSSA-NEXT: [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
73+
; MSSA-NEXT: [[V2:%.*]] = load i8, ptr [[P]], align 1
74+
; MSSA-NEXT: [[SUB:%.*]] = sub i8 [[V1]], [[V2]]
75+
; MSSA-NEXT: call void @escape(ptr [[OBJ]])
76+
; MSSA-NEXT: ret i8 [[SUB]]
4477
;
78+
; CHECK-MSSA-LABEL: @test_opnew(
79+
; CHECK-MSSA-NEXT: [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
80+
; CHECK-MSSA-NEXT: call void @escape(ptr [[OBJ]])
81+
; CHECK-MSSA-NEXT: ret i8 0
4582
%v1 = load i8, ptr %p
4683
%obj = call ptr @_Znwm(i64 16)
4784
%v2 = load i8, ptr %p
@@ -51,3 +88,5 @@ define i8 @test_opnew(ptr %p) {
5188
}
5289

5390

91+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
92+
; CHECK: {{.*}}

llvm/test/Transforms/GVN/pr14166.ll

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1-
; RUN: opt -disable-basic-aa -passes=gvn -S < %s | FileCheck %s
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -disable-basic-aa -passes=gvn -S < %s | FileCheck %s --check-prefixes=CHECK,MDEP
3+
; RUN: opt -disable-basic-aa -passes='gvn<memoryssa;no-memdep>' -S < %s | FileCheck --check-prefixes=CHECK,MSSA %s
24
target datalayout = "e-p:32:32:32"
35
define <2 x i32> @test1() {
6+
; MDEP-LABEL: define <2 x i32> @test1() {
7+
; MDEP-NEXT: [[V1:%.*]] = alloca <2 x i32>, align 8
8+
; MDEP-NEXT: call void @anything(ptr [[V1]])
9+
; MDEP-NEXT: [[V2:%.*]] = load <2 x i32>, ptr [[V1]], align 8
10+
; MDEP-NEXT: [[V3:%.*]] = inttoptr <2 x i32> [[V2]] to <2 x ptr>
11+
; MDEP-NEXT: store <2 x ptr> [[V3]], ptr [[V1]], align 8
12+
; MDEP-NEXT: [[TMP1:%.*]] = bitcast <2 x i32> [[V2]] to i64
13+
; MDEP-NEXT: ret <2 x i32> [[V2]]
14+
;
15+
; MSSA-LABEL: define <2 x i32> @test1() {
16+
; MSSA-NEXT: [[V1:%.*]] = alloca <2 x i32>, align 8
17+
; MSSA-NEXT: call void @anything(ptr [[V1]])
18+
; MSSA-NEXT: [[V2:%.*]] = load <2 x i32>, ptr [[V1]], align 8
19+
; MSSA-NEXT: [[V3:%.*]] = inttoptr <2 x i32> [[V2]] to <2 x ptr>
20+
; MSSA-NEXT: store <2 x ptr> [[V3]], ptr [[V1]], align 8
21+
; MSSA-NEXT: [[V5:%.*]] = load <2 x i32>, ptr [[V1]], align 8
22+
; MSSA-NEXT: ret <2 x i32> [[V5]]
23+
;
24+
; CHECK-MSSA-LABEL: define <2 x i32> @test1() {
25+
; CHECK-MSSA-NEXT: [[V1:%.*]] = alloca <2 x i32>, align 8
26+
; CHECK-MSSA-NEXT: call void @anything(ptr [[V1]])
27+
; CHECK-MSSA-NEXT: [[V2:%.*]] = load <2 x i32>, ptr [[V1]], align 8
28+
; CHECK-MSSA-NEXT: [[V3:%.*]] = inttoptr <2 x i32> [[V2]] to <2 x ptr>
29+
; CHECK-MSSA-NEXT: store <2 x ptr> [[V3]], ptr [[V1]], align 8
30+
; CHECK-MSSA-NEXT: [[TMP1:%.*]] = bitcast <2 x i32> [[V2]] to i64
31+
; CHECK-MSSA-NEXT: ret <2 x i32> [[V2]]
432
%v1 = alloca <2 x i32>
533
call void @anything(ptr %v1)
634
%v2 = load <2 x i32>, ptr %v1
735
%v3 = inttoptr <2 x i32> %v2 to <2 x ptr>
836
store <2 x ptr> %v3, ptr %v1
937
%v5 = load <2 x i32>, ptr %v1
1038
ret <2 x i32> %v5
11-
; CHECK-LABEL: @test1(
12-
; CHECK: %v1 = alloca <2 x i32>
13-
; CHECK: call void @anything(ptr %v1)
14-
; CHECK: %v2 = load <2 x i32>, ptr %v1
15-
; CHECK: %v3 = inttoptr <2 x i32> %v2 to <2 x ptr>
16-
; CHECK: store <2 x ptr> %v3, ptr %v1
17-
; CHECK: ret <2 x i32> %v2
1839
}
1940

2041
declare void @anything(ptr)
2142

43+
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
44+
; CHECK: {{.*}}

0 commit comments

Comments
 (0)