Skip to content

Commit 601cdf7

Browse files
authored
Addition of global-constants.ll, local-aggregrate-constant.ll, local-float-point-constants.ll, local-integers-constants.ll, local-null-constants.ll (#3306)
--Test for constant propagation, global and local constants, from constant subdirectory in llvm project.
1 parent 667e1cb commit 601cdf7

File tree

5 files changed

+237
-0
lines changed

5 files changed

+237
-0
lines changed

test/constant/global-constants.ll

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir64-unknown-unknown"
10+
11+
@global = addrspace(1) constant i32 1 ; OpenCL global memory
12+
@constant = addrspace(2) constant i32 2 ; OpenCL constant memory
13+
@local = addrspace(3) constant i32 3 ; OpenCL local memory
14+
15+
define i32 @getGlobal1() {
16+
%g = load i32, ptr addrspace(1) @global
17+
ret i32 %g
18+
}
19+
20+
define i32 @getGlobal2() {
21+
%g = load i32, ptr addrspace(2) @constant
22+
ret i32 %g
23+
}
24+
25+
define i32 @getGlobal3() {
26+
%g = load i32, ptr addrspace(3) @local
27+
ret i32 %g
28+
}
29+
30+
; CHECK: TypeInt [[#INT:]] 32 0
31+
; CHECK-DAG: Constant [[#INT]] [[#CST_AS1:]] 1
32+
; CHECK-DAG: Constant [[#INT]] [[#CST_AS2:]] 2
33+
; CHECK-DAG: Constant [[#INT]] [[#CST_AS3:]] 3
34+
; CHECK-DAG: TypePointer [[#PTR_TO_INT_AS1:]] 5 [[#INT]]
35+
; CHECK-DAG: TypePointer [[#PTR_TO_INT_AS2:]] 0 [[#INT]]
36+
; CHECK-DAG: TypePointer [[#PTR_TO_INT_AS3:]] 4 [[#INT]]
37+
; CHECK-DAG: Variable [[#PTR_TO_INT_AS1]] [[#GV1:]] 5 [[#CST_AS1]]
38+
; CHECK-DAG: Variable [[#PTR_TO_INT_AS2]] [[#GV2:]] 0 [[#CST_AS2]]
39+
; CHECK-DAG: Variable [[#PTR_TO_INT_AS3]] [[#GV3:]] 4 [[#CST_AS3]]
40+
41+
; CHECK: Load [[#INT]] [[#]] [[#GV1]]
42+
; CHECK: Load [[#INT]] [[#]] [[#GV2]]
43+
; CHECK: Load [[#INT]] [[#]] [[#GV3]]
44+
45+
; CHECK-LLVM: @{{.*}} = addrspace(1) constant i32 1
46+
; CHECK-LLVM: @{{.*}} = addrspace(2) constant i32 2
47+
; CHECK-LLVM: @{{.*}} = addrspace(3) constant i32 3
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir64-unknown-unknown"
10+
11+
%aggregate = type { i8, i32 }
12+
13+
define %aggregate @getConstant() {
14+
ret %aggregate { i8 1, i32 2 }
15+
}
16+
17+
; CHECK: Name [[#GET:]] "getConstant"
18+
; CHECK-DAG: TypeInt [[#I8:]] 8 0
19+
; CHECK-DAG: TypeInt [[#I32:]] 32 0
20+
; CHECK-DAG: Constant [[#I8]] [[#CST_I8:]] 1
21+
; CHECK-DAG: Constant [[#I32]] [[#CST_I32:]] 2
22+
; CHECK-DAG: TypeStruct [[#AGGREGATE:]] [[#I8]] [[#I32]]
23+
; CHECK-DAG: ConstantComposite [[#AGGREGATE]] [[#CST_AGGREGATE:]] [[#CST_I8]] [[#CST_I32]]
24+
25+
; CHECK: Function [[#AGGREGATE]] [[#GET]]
26+
; CHECK: ReturnValue [[#CST_AGGREGATE]]
27+
; CHECK: FunctionEnd
28+
29+
; CHECK-LLVM: ret %{{.*}} { i8 1, i32 2 }
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir64-unknown-unknown"
10+
11+
define half @getConstantFP16() {
12+
ret half 0x3ff1340000000000 ; 0x3c4d represented as double.
13+
}
14+
15+
define float @getConstantFP32() {
16+
ret float 0x3fd27c8be0000000 ; 0x3e93e45f represented as double
17+
}
18+
19+
define double @getConstantFP64() {
20+
ret double 0x4f2de42b8c68f3f1
21+
}
22+
23+
; CHECK: Capability Float16Buffer
24+
; CHECK: Capability Float64
25+
; CHECK: Name [[#FUNC_FP16:]] "getConstantFP16"
26+
; CHECK: Name [[#FUNC_FP32:]] "getConstantFP32"
27+
; CHECK: Name [[#FUNC_FP64:]] "getConstantFP64"
28+
; CHECK: TypeFloat [[#FP16_TY:]] 16
29+
; CHECK: TypeFloat [[#FP32_TY:]] 32
30+
; CHECK: TypeFloat [[#FP64_TY:]] 64
31+
32+
; CHECK: Constant [[#FP16_TY]] [[#FP16_CONST:]] 15437
33+
; CHECK: Constant [[#FP32_TY]] [[#FP32_CONST:]] 1049879647
34+
; CHECK: Constant [[#FP64_TY]] [[#FP64_CONST:]] 2355688433 1328407595
35+
36+
; CHECK: Function [[#FP16_TY]] [[#FUNC_FP16]] 0 [[#]]
37+
; CHECK: ReturnValue [[#FP16_CONST]]
38+
; CHECK: FunctionEnd
39+
40+
; CHECK: Function [[#FP32_TY]] [[#FUNC_FP32]] 0 [[#]]
41+
; CHECK: ReturnValue [[#FP32_CONST]]
42+
; CHECK: FunctionEnd
43+
44+
; CHECK: Function [[#FP64_TY]] [[#FUNC_FP64]] 0 [[#]]
45+
; CHECK: ReturnValue [[#FP64_CONST]]
46+
; CHECK: FunctionEnd
47+
48+
; CHECK-LLVM: ret half 0xH3C4D
49+
; CHECK-LLVM: ret float 0x3FD27C8BE0000000
50+
; CHECK-LLVM: ret double 0x4F2DE42B8C68F3F1
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir64-unknown-unknown"
10+
11+
define i8 @getConstantI8() {
12+
ret i8 2
13+
}
14+
15+
define i16 @getConstantI16() {
16+
ret i16 -58
17+
}
18+
19+
define i32 @getConstantI32() {
20+
ret i32 42
21+
}
22+
23+
define i64 @getConstantI64() {
24+
ret i64 123456789
25+
}
26+
27+
define i64 @getLargeConstantI64() {
28+
ret i64 34359738368
29+
}
30+
31+
; CHECK: Capability Int64
32+
; CHECK: Capability Int16
33+
; CHECK: Capability Int8
34+
; CHECK: Name [[#I8_FUNC:]] "getConstantI8"
35+
; CHECK: Name [[#I16_FUNC:]] "getConstantI16"
36+
; CHECK: Name [[#I32_FUNC:]] "getConstantI32"
37+
; CHECK: Name [[#I64_FUNC:]] "getConstantI64"
38+
; CHECK: Name [[#LARGE_I64_FUNC:]] "getLargeConstantI64"
39+
40+
; CHECK: TypeInt [[#I8_TY:]] 8 0
41+
; CHECK: TypeInt [[#I16_TY:]] 16 0
42+
; CHECK: TypeInt [[#I32_TY:]] 32 0
43+
; CHECK: TypeInt [[#I64_TY:]] 64 0
44+
; CHECK: Constant [[#I8_TY]] [[#I8_CONST:]] 2
45+
; CHECK: Constant [[#I16_TY]] [[#I16_CONST:]] 65478
46+
; CHECK: Constant [[#I32_TY]] [[#I32_CONST:]] 42
47+
; CHECK: Constant [[#I64_TY]] [[#I64_CONST:]] 123456789 0
48+
; For 34359738368 = 0x00000008 00000000, so represented as 0 8
49+
; CHECK: Constant [[#I64_TY]] [[#LARGE_I64_CONST:]] 0 8
50+
51+
; CHECK: Function [[#I8_TY]] [[#I8_FUNC]] 0 [[#]]
52+
; CHECK: ReturnValue [[#I8_CONST]]
53+
; CHECK: FunctionEnd
54+
55+
; CHECK: Function [[#I16_TY]] [[#I16_FUNC]] 0 [[#]]
56+
; CHECK: ReturnValue [[#I16_CONST]]
57+
; CHECK: FunctionEnd
58+
59+
; CHECK: Function [[#I32_TY]] [[#I32_FUNC]] 0 [[#]]
60+
; CHECK: ReturnValue [[#I32_CONST]]
61+
; CHECK: FunctionEnd
62+
63+
; CHECK: Function [[#I64_TY]] [[#I64_FUNC]] 0 [[#]]
64+
; CHECK: ReturnValue [[#I64_CONST]]
65+
; CHECK: FunctionEnd
66+
67+
; CHECK: Function [[#I64_TY]] [[#LARGE_I64_FUNC]] 0 [[#]]
68+
; CHECK: ReturnValue [[#LARGE_I64_CONST]]
69+
; CHECK: FunctionEnd
70+
71+
; CHECK-LLVM: ret i8 2
72+
; CHECK-LLVM: ret i16 -58
73+
; CHECK-LLVM: ret i32 42
74+
; CHECK-LLVM: ret i64 123456789
75+
; CHECK-LLVM: ret i64 34359738368
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: llvm-as < %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -to-text %t.spv -o - | FileCheck %s
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir64-unknown-unknown"
10+
11+
;; OpenCL global memory
12+
define ptr addrspace(1) @getConstant1() {
13+
ret ptr addrspace(1) null
14+
}
15+
16+
;; OpenCL constant memory
17+
define ptr addrspace(2) @getConstant2() {
18+
ret ptr addrspace(2) null
19+
}
20+
21+
;; OpenCL local memory
22+
define ptr addrspace(3) @getConstant3() {
23+
ret ptr addrspace(3) null
24+
}
25+
26+
; CHECK: TypeInt [[#I8_TY:]] 8 0
27+
; CHECK: TypePointer [[#PTR_TY1:]] 5 [[#I8_TY]]
28+
; CHECK: TypePointer [[#PTR_TY2:]] 0 [[#I8_TY]]
29+
; CHECK: TypePointer [[#PTR_TY3:]] 4 [[#I8_TY]]
30+
; CHECK: ConstantNull [[#PTR_TY1]] [[#NULL1:]]
31+
; CHECK: ConstantNull [[#PTR_TY2]] [[#NULL2:]]
32+
; CHECK: ConstantNull [[#PTR_TY3]] [[#NULL3:]]
33+
34+
; CHECK-LLVM: ret ptr addrspace(1) null
35+
; CHECK-LLVM: ret ptr addrspace(2) null
36+
; CHECK-LLVM: ret ptr addrspace(3) null

0 commit comments

Comments
 (0)