Skip to content

[SPIRV][HLSL] Add HLSL intrinsic tests #86844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/SPIRV/hlsl-intrinsics/abs.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/ceil.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @ceil_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Ceil %[[#]]
%elt.ceil = call float @llvm.ceil.f32(float %a)
ret float %elt.ceil
}

define noundef half @ceil_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Ceil %[[#]]
%elt.ceil = call half @llvm.ceil.f16(half %a)
ret half %elt.ceil
}

declare half @llvm.ceil.f16(half)
declare float @llvm.ceil.f32(float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cos.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @cos_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Cos %[[#]]
%elt.cos = call float @llvm.cos.f32(float %a)
ret float %elt.cos
}

define noundef half @cos_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Cos %[[#]]
%elt.cos = call half @llvm.cos.f16(half %a)
ret half %elt.cos
}

declare half @llvm.cos.f16(half)
declare float @llvm.cos.f32(float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/exp.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @exp_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp %[[#]]
%elt.exp = call float @llvm.exp.f32(float %a)
ret float %elt.exp
}

define noundef half @exp_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp %[[#]]
%elt.exp = call half @llvm.exp.f16(half %a)
ret half %elt.exp
}

declare half @llvm.exp.f16(half)
declare float @llvm.exp.f32(float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/exp2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @exp2_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp2 %[[#]]
%elt.exp2 = call float @llvm.exp2.f32(float %a)
ret float %elt.exp2
}

define noundef half @exp2_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Exp2 %[[#]]
%elt.exp2 = call half @llvm.exp2.f16(half %a)
ret half %elt.exp2
}

declare half @llvm.exp2.f16(half)
declare float @llvm.exp2.f32(float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/floor.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @floor_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Floor %[[#]]
%elt.floor = call float @llvm.floor.f32(float %a)
ret float %elt.floor
}

define noundef half @floor_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Floor %[[#]]
%elt.floor = call half @llvm.floor.f16(half %a)
ret half %elt.floor
}

declare half @llvm.floor.f16(half)
declare float @llvm.floor.f32(float)
29 changes: 29 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmad.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef half @fmad_half(half noundef %a, half noundef %b, half noundef %c) #0 {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Fma %[[#]] %[[#]] %[[#]]
%dx.fmad = call half @llvm.fmuladd.f16(half %a, half %b, half %c)
ret half %dx.fmad
}

define noundef float @fmad_float(float noundef %a, float noundef %b, float noundef %c) #0 {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Fma %[[#]] %[[#]] %[[#]]
%dx.fmad = call float @llvm.fmuladd.f32(float %a, float %b, float %c)
ret float %dx.fmad
}

define noundef double @fmad_double(double noundef %a, double noundef %b, double noundef %c) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Fma %[[#]] %[[#]] %[[#]]
%dx.fmad = call double @llvm.fmuladd.f64(double %a, double %b, double %c)
ret double %dx.fmad
}

declare half @llvm.fmuladd.f16(half, half, half)
declare float @llvm.fmuladd.f32(float, float, float)
declare double @llvm.fmuladd.f64(double, double, double)
29 changes: 29 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; TODO: This need to be NMax: See https://github.com/llvm/llvm-project/issues/87072
; CHECK: OpExtInstImport "GLSL.std.450"

define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
%0 = call half @llvm.maxnum.f16(half %a, half %b)
ret half %0
}

define noundef float @test_fmax_float(float noundef %a, float noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
%0 = call float @llvm.maxnum.f32(float %a, float %b)
ret float %0
}

define noundef double @test_fmax_double(double noundef %a, double noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
%0 = call double @llvm.maxnum.f64(double %a, double %b)
ret double %0
}

declare half @llvm.maxnum.f16(half, half)
declare float @llvm.maxnum.f32(float, float)
declare double @llvm.maxnum.f64(double, double)
31 changes: 31 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; TODO: This need to be NMin: See https://github.com/llvm/llvm-project/issues/87072

; CHECK: OpExtInstImport "GLSL.std.450"
; CHECK: OpMemoryModel Logical GLSL450

define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
%0 = call half @llvm.minnum.f16(half %a, half %b)
ret half %0
}

define noundef float @test_fmax_float(float noundef %a, float noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
%0 = call float @llvm.minnum.f32(float %a, float %b)
ret float %0
}

define noundef double @test_fmax_double(double noundef %a, double noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
%0 = call double @llvm.minnum.f64(double %a, double %b)
ret double %0
}

declare half @llvm.minnum.f16(half, half)
declare float @llvm.minnum.f32(float, float)
declare double @llvm.minnum.f64(double, double)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/log.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @log_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log %[[#]]
%elt.log = call float @llvm.log.f32(float %a)
ret float %elt.log
}

define noundef half @log_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log %[[#]]
%elt.log = call half @llvm.log.f16(half %a)
ret half %elt.log
}

declare half @llvm.log.f16(half)
declare float @llvm.log.f32(float)
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/SPIRV/hlsl-intrinsics/log10.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: %[[#extinst:]] = OpExtInstImport "GLSL.std.450"

Expand Down
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/log2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @log2_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log2 %[[#]]
%elt.log2 = call float @llvm.log2.f32(float %a)
ret float %elt.log2
}

define noundef half @log2_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Log2 %[[#]]
%elt.log2 = call half @llvm.log2.f16(half %a)
ret half %elt.log2
}

declare half @llvm.log2.f16(half)
declare float @llvm.log2.f32(float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/pow.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @pow_float(float noundef %a,float noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Pow %[[#]]
%elt.pow = call float @llvm.pow.f32(float %a,float %b)
ret float %elt.pow
}

define noundef half @pow_half(half noundef %a, half noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Pow %[[#]]
%elt.pow = call half @llvm.pow.f16(half %a, half %b)
ret half %elt.pow
}

declare half @llvm.pow.f16(half,half)
declare float @llvm.pow.f32(float,float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/reversebits.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpMemoryModel Logical GLSL450

define noundef i32 @reversebits_i32(i32 noundef %a) {
entry:
; CHECK: %[[#]] = OpBitReverse %[[#]] %[[#]]
%elt.bitreverse = call i32 @llvm.bitreverse.i32(i32 %a)
ret i32 %elt.bitreverse
}

define noundef i16 @reversebits_i16(i16 noundef %a) {
entry:
; CHECK: %[[#]] = OpBitReverse %[[#]] %[[#]]
%elt.bitreverse = call i16 @llvm.bitreverse.i16(i16 %a)
ret i16 %elt.bitreverse
}

declare i16 @llvm.bitreverse.i16(i16)
declare i32 @llvm.bitreverse.i32(i32)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/round.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @round_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] RoundEven %[[#]]
%elt.roundeven = call float @llvm.roundeven.f32(float %a)
ret float %elt.roundeven
}

define noundef half @round_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] RoundEven %[[#]]
%elt.roundeven = call half @llvm.roundeven.f16(half %a)
ret half %elt.roundeven
}

declare half @llvm.roundeven.f16(half)
declare float @llvm.roundeven.f32(float)
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/sin.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef float @sin_float(float noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Sin %[[#]]
%elt.sin = call float @llvm.sin.f32(float %a)
ret float %elt.sin
}

define noundef half @sin_half(half noundef %a) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] Sin %[[#]]
%elt.sin = call half @llvm.sin.f16(half %a)
ret half %elt.sin
}

declare half @llvm.sin.f16(half)
declare float @llvm.sin.f32(float)
29 changes: 29 additions & 0 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/smax.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: OpExtInstImport "GLSL.std.450"

define noundef i16 @test_smax_i16(i16 noundef %a, i16 noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMax %[[#]] %[[#]]
%0 = call i16 @llvm.smax.i16(i16 %a, i16 %b)
ret i16 %0
}

define noundef i32 @test_smax_i32(i32 noundef %a, i32 noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMax %[[#]] %[[#]]
%0 = call i32 @llvm.smax.i32(i32 %a, i32 %b)
ret i32 %0
}

define noundef i64 @test_smax_i64(i64 noundef %a, i64 noundef %b) {
entry:
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SMax %[[#]] %[[#]]
%0 = call i64 @llvm.smax.i64(i64 %a, i64 %b)
ret i64 %0
}

declare i16 @llvm.smax.i16(i16, i16)
declare i32 @llvm.smax.i32(i32, i32)
declare i64 @llvm.smax.i64(i64, i64)
Loading