Skip to content

Commit 0962e7f

Browse files
svenvhvmaksimo
authored andcommitted
Handle OpSpecConstantOp with SMod
Original commit: KhronosGroup/SPIRV-LLVM-Translator@29cc2bb
1 parent 5e5685e commit 0962e7f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,10 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
24842484
// r = srem(a, b)
24852485
// needs_fixing = ((a < 0) != (b < 0) && r != 0)
24862486
// result = needs_fixing ? r + b : r
2487-
IRBuilder<> Builder(BB);
2487+
IRBuilder<> Builder(*Context);
2488+
if (BB) {
2489+
Builder.SetInsertPoint(BB);
2490+
}
24882491
SPIRVSMod *SMod = static_cast<SPIRVSMod *>(BV);
24892492
auto Dividend = transValue(SMod->getOperand(0), F, BB);
24902493
auto Divisor = transValue(SMod->getOperand(1), F, BB);

llvm-spirv/test/SpecConstants/specconstantop-init.spvasm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
; CHECK: @var_sdiv0 = addrspace(1) global i32 poison
2323
; CHECK: @var_umod = addrspace(1) global i32 1
2424
; CHECK: @var_srem = addrspace(1) global i32 1
25-
; TODO: smod
25+
; CHECK: @var_smod = addrspace(1) global i32 -3
2626
; CHECK: @var_srl = addrspace(1) global i32 268435455
2727
; CHECK: @var_sra = addrspace(1) global i32 -1
2828
; CHECK: @var_sll = addrspace(1) global i32 848
@@ -67,6 +67,7 @@
6767
OpDecorate %var_sdiv0 LinkageAttributes "var_sdiv0" Export
6868
OpDecorate %var_umod LinkageAttributes "var_umod" Export
6969
OpDecorate %var_srem LinkageAttributes "var_srem" Export
70+
OpDecorate %var_smod LinkageAttributes "var_smod" Export
7071
OpDecorate %var_srl LinkageAttributes "var_srl" Export
7172
OpDecorate %var_sra LinkageAttributes "var_sra" Export
7273
OpDecorate %var_sll LinkageAttributes "var_sll" Export
@@ -114,6 +115,7 @@
114115
%sdiv0 = OpSpecConstantOp %uint SDiv %uint_53 %uint_0
115116
%umod = OpSpecConstantOp %uint UMod %uint_53 %uint_4
116117
%srem = OpSpecConstantOp %uint SRem %uint_53 %uint_min4
118+
%smod = OpSpecConstantOp %uint SMod %uint_53 %uint_min4
117119
%srl = OpSpecConstantOp %uint ShiftRightLogical %uint_min4 %uint_4
118120
%sra = OpSpecConstantOp %uint ShiftRightArithmetic %uint_min4 %uint_4
119121
%sll = OpSpecConstantOp %uint ShiftLeftLogical %uint_53 %uint_4
@@ -156,6 +158,7 @@
156158
%var_sdiv0 = OpVariable %_ptr_uint CrossWorkgroup %sdiv0
157159
%var_umod = OpVariable %_ptr_uint CrossWorkgroup %umod
158160
%var_srem = OpVariable %_ptr_uint CrossWorkgroup %srem
161+
%var_smod = OpVariable %_ptr_uint CrossWorkgroup %smod
159162
%var_srl = OpVariable %_ptr_uint CrossWorkgroup %srl
160163
%var_sra = OpVariable %_ptr_uint CrossWorkgroup %sra
161164
%var_sll = OpVariable %_ptr_uint CrossWorkgroup %sll

0 commit comments

Comments
 (0)