Skip to content

Commit d21b77f

Browse files
committed
[SPIRV][HLSL] Add HLSL intrinsic tests
This PR is part of bookkeeping for #83882. It also brings the SPIRV hlsl intrinsics tests in parity with where the testing is on the DXIL backend.
1 parent ff870ae commit d21b77f

File tree

20 files changed

+463
-0
lines changed

20 files changed

+463
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @ceil_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Ceil %[[#]]
8+
%elt.ceil = call float @llvm.ceil.f32(float %a)
9+
ret float %elt.ceil
10+
}
11+
12+
define noundef half @ceil_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Ceil %[[#]]
15+
%elt.ceil = call half @llvm.ceil.f16(half %a)
16+
ret half %elt.ceil
17+
}
18+
19+
declare half @llvm.ceil.f16(half)
20+
declare float @llvm.ceil.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @cos_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Cos %[[#]]
8+
%elt.cos = call float @llvm.cos.f32(float %a)
9+
ret float %elt.cos
10+
}
11+
12+
define noundef half @cos_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Cos %[[#]]
15+
%elt.cos = call half @llvm.cos.f16(half %a)
16+
ret half %elt.cos
17+
}
18+
19+
declare half @llvm.cos.f16(half)
20+
declare float @llvm.cos.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @exp_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp %[[#]]
8+
%elt.exp = call float @llvm.exp.f32(float %a)
9+
ret float %elt.exp
10+
}
11+
12+
define noundef half @exp_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp %[[#]]
15+
%elt.exp = call half @llvm.exp.f16(half %a)
16+
ret half %elt.exp
17+
}
18+
19+
declare half @llvm.exp.f16(half)
20+
declare float @llvm.exp.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @exp2_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp2 %[[#]]
8+
%elt.exp2 = call float @llvm.exp2.f32(float %a)
9+
ret float %elt.exp2
10+
}
11+
12+
define noundef half @exp2_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp2 %[[#]]
15+
%elt.exp2 = call half @llvm.exp2.f16(half %a)
16+
ret half %elt.exp2
17+
}
18+
19+
declare half @llvm.exp2.f16(half)
20+
declare float @llvm.exp2.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @floor_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Floor %[[#]]
8+
%elt.floor = call float @llvm.floor.f32(float %a)
9+
ret float %elt.floor
10+
}
11+
12+
define noundef half @floor_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Floor %[[#]]
15+
%elt.floor = call half @llvm.floor.f16(half %a)
16+
ret half %elt.floor
17+
}
18+
19+
declare half @llvm.floor.f16(half)
20+
declare float @llvm.floor.f32(float)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef half @fmad_half(half noundef %a, half noundef %b, half noundef %c) #0 {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Fma %[[#]] %[[#]] %[[#]]
8+
%dx.fmad = call half @llvm.fmuladd.f16(half %a, half %b, half %c)
9+
ret half %dx.fmad
10+
}
11+
12+
define noundef float @fmad_float(float noundef %a, float noundef %b, float noundef %c) #0 {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Fma %[[#]] %[[#]] %[[#]]
15+
%dx.fmad = call float @llvm.fmuladd.f32(float %a, float %b, float %c)
16+
ret float %dx.fmad
17+
}
18+
19+
define noundef double @fmad_double(double noundef %a, double noundef %b, double noundef %c) {
20+
entry:
21+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Fma %[[#]] %[[#]] %[[#]]
22+
%dx.fmad = call double @llvm.fmuladd.f64(double %a, double %b, double %c)
23+
ret double %dx.fmad
24+
}
25+
26+
declare half @llvm.fmuladd.f16(half, half, half)
27+
declare float @llvm.fmuladd.f32(float, float, float)
28+
declare double @llvm.fmuladd.f64(double, double, double)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
8+
%0 = call half @llvm.maxnum.f16(half %a, half %b)
9+
ret half %0
10+
}
11+
12+
define noundef float @test_fmax_float(float noundef %a, float noundef %b) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
15+
%0 = call float @llvm.maxnum.f32(float %a, float %b)
16+
ret float %0
17+
}
18+
19+
define noundef double @test_fmax_double(double noundef %a, double noundef %b) {
20+
entry:
21+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
22+
%0 = call double @llvm.maxnum.f64(double %a, double %b)
23+
ret double %0
24+
}
25+
26+
declare half @llvm.maxnum.f16(half, half)
27+
declare float @llvm.maxnum.f32(float, float)
28+
declare double @llvm.maxnum.f64(double, double)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
; CHECK: OpMemoryModel Logical GLSL450
5+
6+
define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
7+
entry:
8+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
9+
%0 = call half @llvm.minnum.f16(half %a, half %b)
10+
ret half %0
11+
}
12+
13+
define noundef float @test_fmax_float(float noundef %a, float noundef %b) {
14+
entry:
15+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
16+
%0 = call float @llvm.minnum.f32(float %a, float %b)
17+
ret float %0
18+
}
19+
20+
define noundef double @test_fmax_double(double noundef %a, double noundef %b) {
21+
entry:
22+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
23+
%0 = call double @llvm.minnum.f64(double %a, double %b)
24+
ret double %0
25+
}
26+
27+
declare half @llvm.minnum.f16(half, half)
28+
declare float @llvm.minnum.f32(float, float)
29+
declare double @llvm.minnum.f64(double, double)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @log_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log %[[#]]
8+
%elt.log = call float @llvm.log.f32(float %a)
9+
ret float %elt.log
10+
}
11+
12+
define noundef half @log_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log %[[#]]
15+
%elt.log = call half @llvm.log.f16(half %a)
16+
ret half %elt.log
17+
}
18+
19+
declare half @llvm.log.f16(half)
20+
declare float @llvm.log.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @log2_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log2 %[[#]]
8+
%elt.log2 = call float @llvm.log2.f32(float %a)
9+
ret float %elt.log2
10+
}
11+
12+
define noundef half @log2_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log2 %[[#]]
15+
%elt.log2 = call half @llvm.log2.f16(half %a)
16+
ret half %elt.log2
17+
}
18+
19+
declare half @llvm.log2.f16(half)
20+
declare float @llvm.log2.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @pow_float(float noundef %a,float noundef %b) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Pow %[[#]]
8+
%elt.pow = call float @llvm.pow.f32(float %a,float %b)
9+
ret float %elt.pow
10+
}
11+
12+
define noundef half @pow_half(half noundef %a, half noundef %b) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Pow %[[#]]
15+
%elt.pow = call half @llvm.pow.f16(half %a, half %b)
16+
ret half %elt.pow
17+
}
18+
19+
declare half @llvm.pow.f16(half,half)
20+
declare float @llvm.pow.f32(float,float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpMemoryModel Logical GLSL450
4+
5+
define noundef i32 @reversebits_i32(i32 noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpBitReverse %[[#]] %[[#]]
8+
%elt.bitreverse = call i32 @llvm.bitreverse.i32(i32 %a)
9+
ret i32 %elt.bitreverse
10+
}
11+
12+
define noundef i16 @reversebits_i16(i16 noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpBitReverse %[[#]] %[[#]]
15+
%elt.bitreverse = call i16 @llvm.bitreverse.i16(i16 %a)
16+
ret i16 %elt.bitreverse
17+
}
18+
19+
declare i16 @llvm.bitreverse.i16(i16)
20+
declare i32 @llvm.bitreverse.i32(i32)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @round_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Round %[[#]]
8+
%elt.round = call float @llvm.round.f32(float %a)
9+
ret float %elt.round
10+
}
11+
12+
define noundef half @round_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Round %[[#]]
15+
%elt.round = call half @llvm.round.f16(half %a)
16+
ret half %elt.round
17+
}
18+
19+
declare half @llvm.round.f16(half)
20+
declare float @llvm.round.f32(float)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef float @sin_float(float noundef %a) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Sin %[[#]]
8+
%elt.sin = call float @llvm.sin.f32(float %a)
9+
ret float %elt.sin
10+
}
11+
12+
define noundef half @sin_half(half noundef %a) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Sin %[[#]]
15+
%elt.sin = call half @llvm.sin.f16(half %a)
16+
ret half %elt.sin
17+
}
18+
19+
declare half @llvm.sin.f16(half)
20+
declare float @llvm.sin.f32(float)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define noundef i16 @test_smax_i16(i16 noundef %a, i16 noundef %b) {
6+
entry:
7+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMax %[[#]] %[[#]]
8+
%0 = call i16 @llvm.smax.i16(i16 %a, i16 %b)
9+
ret i16 %0
10+
}
11+
12+
define noundef i32 @test_smax_i32(i32 noundef %a, i32 noundef %b) {
13+
entry:
14+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMax %[[#]] %[[#]]
15+
%0 = call i32 @llvm.smax.i32(i32 %a, i32 %b)
16+
ret i32 %0
17+
}
18+
19+
define noundef i64 @test_smax_i64(i64 noundef %a, i64 noundef %b) {
20+
entry:
21+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMax %[[#]] %[[#]]
22+
%0 = call i64 @llvm.smax.i64(i64 %a, i64 %b)
23+
ret i64 %0
24+
}
25+
26+
declare i16 @llvm.smax.i16(i16, i16)
27+
declare i32 @llvm.smax.i32(i32, i32)
28+
declare i64 @llvm.smax.i64(i64, i64)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
6+
define noundef i16 @test_smin_i16(i16 noundef %a, i16 noundef %b) {
7+
entry:
8+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMin %[[#]] %[[#]]
9+
%0 = call i16 @llvm.smin.i16(i16 %a, i16 %b)
10+
ret i16 %0
11+
}
12+
13+
14+
define noundef i32 @test_smin_i32(i32 noundef %a, i32 noundef %b) {
15+
entry:
16+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMin %[[#]] %[[#]]
17+
%0 = call i32 @llvm.smin.i32(i32 %a, i32 %b)
18+
ret i32 %0
19+
}
20+
21+
22+
define noundef i64 @test_smin_i64(i64 noundef %a, i64 noundef %b) {
23+
entry:
24+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMin %[[#]] %[[#]]
25+
%0 = call i64 @llvm.smin.i64(i64 %a, i64 %b)
26+
ret i64 %0
27+
}
28+
29+
declare i16 @llvm.smin.i16(i16, i16)
30+
declare i32 @llvm.smin.i32(i32, i32)
31+
declare i64 @llvm.smin.i64(i64, i64)

0 commit comments

Comments
 (0)