Skip to content

Commit 010cf37

Browse files
committed
Added radians selection for spirv
1 parent e379b4b commit 010cf37

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ let TargetPrefix = "spv" in {
8383
[IntrNoMem, Commutative] >;
8484
def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
8585
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
86+
def int_spv_radians : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]>;
8687
}

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ class SPIRVInstructionSelector : public InstructionSelector {
229229
bool selectSpvThreadId(Register ResVReg, const SPIRVType *ResType,
230230
MachineInstr &I) const;
231231

232+
bool selectRadians(Register ResVReg, const SPIRVType *ResType,
233+
MachineInstr &I) const;
234+
232235
bool selectUnmergeValues(MachineInstr &I) const;
233236

234237
// Utilities
@@ -1751,6 +1754,45 @@ bool SPIRVInstructionSelector::selectSign(Register ResVReg,
17511754
return Result;
17521755
}
17531756

1757+
<<<<<<< HEAD
1758+
=======
1759+
bool SPIRVInstructionSelector::selectStep(Register ResVReg,
1760+
const SPIRVType *ResType,
1761+
MachineInstr &I) const {
1762+
1763+
assert(I.getNumOperands() == 4);
1764+
assert(I.getOperand(2).isReg());
1765+
assert(I.getOperand(3).isReg());
1766+
MachineBasicBlock &BB = *I.getParent();
1767+
1768+
return BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpExtInst))
1769+
.addDef(ResVReg)
1770+
.addUse(GR.getSPIRVTypeID(ResType))
1771+
.addImm(static_cast<uint32_t>(SPIRV::InstructionSet::GLSL_std_450))
1772+
.addImm(GL::Step)
1773+
.addUse(I.getOperand(2).getReg())
1774+
.addUse(I.getOperand(3).getReg())
1775+
.constrainAllUses(TII, TRI, RBI);
1776+
}
1777+
1778+
bool SPIRVInstructionSelector::selectRadians(Register ResVReg,
1779+
const SPIRVType *ResType,
1780+
MachineInstr &I) const {
1781+
1782+
assert(I.getNumOperands() == 3);
1783+
assert(I.getOperand(2).isReg());
1784+
MachineBasicBlock &BB = *I.getParent();
1785+
1786+
return BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpExtInst))
1787+
.addDef(ResVReg)
1788+
.addUse(GR.getSPIRVTypeID(ResType))
1789+
.addImm(static_cast<uint32_t>(SPIRV::InstructionSet::GLSL_std_450))
1790+
.addImm(GL::Radians)
1791+
.addUse(I.getOperand(2).getReg())
1792+
.constrainAllUses(TII, TRI, RBI);
1793+
}
1794+
1795+
>>>>>>> c520937ac3f9 (Added radians selection for spirv)
17541796
bool SPIRVInstructionSelector::selectBitreverse(Register ResVReg,
17551797
const SPIRVType *ResType,
17561798
MachineInstr &I) const {
@@ -2533,6 +2575,7 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25332575
.addUse(GR.getOrCreateConstInt(3, I, IntTy, TII));
25342576
}
25352577
case Intrinsic::spv_step:
2578+
<<<<<<< HEAD
25362579
return selectExtInst(ResVReg, ResType, I, CL::step, GL::Step);
25372580
// Discard intrinsics which we do not expect to actually represent code after
25382581
// lowering or intrinsics which are not implemented but should not crash when
@@ -2542,6 +2585,11 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25422585
case Intrinsic::instrprof_value_profile:
25432586
break;
25442587
// Discard internal intrinsics.
2588+
=======
2589+
return selectStep(ResVReg, ResType, I);
2590+
case Intrinsic::spv_radians:
2591+
return selectRadians(ResVReg, ResType, I);
2592+
>>>>>>> c520937ac3f9 (Added radians selection for spirv)
25452593
case Intrinsic::spv_value_md:
25462594
break;
25472595
default: {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "GLSL.std.450"
5+
6+
; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
7+
; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
8+
9+
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
10+
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
11+
12+
declare half @llvm.spv.radians.f16(half)
13+
declare float @llvm.spv.radians.f32(float)
14+
15+
declare <4 x float> @llvm.spv.radians.v4f32(<4 x float>)
16+
declare <4 x half> @llvm.spv.radians.v4f16(<4 x half>)
17+
18+
define noundef float @radians_float(float noundef %a) {
19+
entry:
20+
; CHECK: %[[#float_32_arg:]] = OpFunctionParameter %[[#float_32]]
21+
; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Radians %[[#float_32_arg]]
22+
%elt.radians = call float @llvm.spv.radians.f32(float %a)
23+
ret float %elt.radians
24+
}
25+
26+
define noundef half @radians_half(half noundef %a) {
27+
entry:
28+
; CHECK: %[[#float_16_arg:]] = OpFunctionParameter %[[#float_16]]
29+
; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Radians %[[#float_16_arg]]
30+
%elt.radians = call half @llvm.spv.radians.f16(half %a)
31+
ret half %elt.radians
32+
}
33+
34+
define noundef <4 x float> @radians_float_vector(<4 x float> noundef %a) {
35+
entry:
36+
; CHECK: %[[#vec4_float_32_arg:]] = OpFunctionParameter %[[#vec4_float_32]]
37+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] Radians %[[#vec4_float_32_arg]]
38+
%elt.radians = call <4 x float> @llvm.spv.radians.v4f32(<4 x float> %a)
39+
ret <4 x float> %elt.radians
40+
}
41+
42+
define noundef <4 x half> @radians_half_vector(<4 x half> noundef %a) {
43+
entry:
44+
; CHECK: %[[#vec4_float_16_arg:]] = OpFunctionParameter %[[#vec4_float_16]]
45+
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] Radians %[[#vec4_float_16_arg]]
46+
%elt.radians = call <4 x half> @llvm.spv.radians.v4f16(<4 x half> %a)
47+
ret <4 x half> %elt.radians
48+
}

0 commit comments

Comments
 (0)