Skip to content

Commit b6e2bcc

Browse files
committed
Handle OpSpecConstantOp for SNegate, Not, and LogicalNot
1 parent cb7a560 commit b6e2bcc

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,10 +2443,16 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
24432443
}
24442444

24452445
case OpSNegate: {
2446+
IRBuilder<> Builder(*Context);
2447+
if (BB) {
2448+
Builder.SetInsertPoint(BB);
2449+
}
24462450
SPIRVUnary *BC = static_cast<SPIRVUnary *>(BV);
2447-
auto Neg = BinaryOperator::CreateNeg(transValue(BC->getOperand(0), F, BB),
2448-
BV->getName(), BB);
2449-
applyNoIntegerWrapDecorations(BV, Neg);
2451+
auto Neg =
2452+
Builder.CreateNeg(transValue(BC->getOperand(0), F, BB), BV->getName());
2453+
if (auto *NegInst = dyn_cast<Instruction>(Neg)) {
2454+
applyNoIntegerWrapDecorations(BV, NegInst);
2455+
}
24502456
return mapValue(BV, Neg);
24512457
}
24522458

@@ -2499,10 +2505,13 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
24992505

25002506
case OpNot:
25012507
case OpLogicalNot: {
2508+
IRBuilder<> Builder(*Context);
2509+
if (BB) {
2510+
Builder.SetInsertPoint(BB);
2511+
}
25022512
SPIRVUnary *BC = static_cast<SPIRVUnary *>(BV);
2503-
return mapValue(
2504-
BV, BinaryOperator::CreateNot(transValue(BC->getOperand(0), F, BB),
2505-
BV->getName(), BB));
2513+
return mapValue(BV, Builder.CreateNot(transValue(BC->getOperand(0), F, BB),
2514+
BV->getName()));
25062515
}
25072516

25082517
case OpAll:

test/SpecConstants/specconstantop-init.spvasm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
; operations are supported. Also verify that edge cases such as division
1010
; by zero are handled gracefully.
1111

12+
; CHECK: @var_snegate = addrspace(1) global i32 -53
13+
; CHECK: @var_not = addrspace(1) global i32 -54
1214
; CHECK: @var_iadd = addrspace(1) global i32 49
1315
; CHECK: @var_isub = addrspace(1) global i32 57
1416
; CHECK: @var_imul = addrspace(1) global i32 -212
@@ -28,13 +30,16 @@
2830
; CHECK: @var_bitand = addrspace(1) global i32 52
2931
; CHECK: @var_logor = addrspace(1) global i1 true
3032
; CHECK: @var_logand = addrspace(1) global i1 false
33+
; CHECK: @var_lognot = addrspace(1) global i1 false
3134

3235
OpCapability Addresses
3336
OpCapability Linkage
3437
OpCapability Kernel
3538
OpMemoryModel Physical32 OpenCL
3639
OpEntryPoint Kernel %15 "foo"
3740
OpName %entry "entry"
41+
OpDecorate %var_snegate LinkageAttributes "var_snegate" Export
42+
OpDecorate %var_not LinkageAttributes "var_not" Export
3843
OpDecorate %var_iadd LinkageAttributes "var_iadd" Export
3944
OpDecorate %var_isub LinkageAttributes "var_isub" Export
4045
OpDecorate %var_imul LinkageAttributes "var_imul" Export
@@ -53,6 +58,7 @@
5358
OpDecorate %var_bitand LinkageAttributes "var_bitand" Export
5459
OpDecorate %var_logor LinkageAttributes "var_logor" Export
5560
OpDecorate %var_logand LinkageAttributes "var_logand" Export
61+
OpDecorate %var_lognot LinkageAttributes "var_lognot" Export
5662
%bool = OpTypeBool
5763
%true = OpConstantTrue %bool
5864
%false = OpConstantFalse %bool
@@ -61,6 +67,8 @@
6167
%uint_4 = OpConstant %uint 4
6268
%uint_53 = OpConstant %uint 53
6369
%uint_min4 = OpConstant %uint 0xfffffffc
70+
%snegate = OpSpecConstantOp %uint SNegate %uint_53
71+
%not = OpSpecConstantOp %uint Not %uint_53
6472
%iadd = OpSpecConstantOp %uint IAdd %uint_53 %uint_min4
6573
%isub = OpSpecConstantOp %uint ISub %uint_53 %uint_min4
6674
%imul = OpSpecConstantOp %uint IMul %uint_53 %uint_min4
@@ -79,11 +87,14 @@
7987
%bitand = OpSpecConstantOp %uint BitwiseAnd %uint_53 %uint_min4
8088
%logor = OpSpecConstantOp %bool LogicalOr %true %false
8189
%logand = OpSpecConstantOp %bool LogicalAnd %true %false
90+
%lognot = OpSpecConstantOp %bool LogicalNot %true
8291
%_ptr_uint = OpTypePointer CrossWorkgroup %uint
8392
%_ptr_bool = OpTypePointer CrossWorkgroup %bool
8493
%void = OpTypeVoid
8594
%14 = OpTypeFunction %void
8695

96+
%var_snegate = OpVariable %_ptr_uint CrossWorkgroup %snegate
97+
%var_not = OpVariable %_ptr_uint CrossWorkgroup %not
8798
%var_iadd = OpVariable %_ptr_uint CrossWorkgroup %iadd
8899
%var_isub = OpVariable %_ptr_uint CrossWorkgroup %isub
89100
%var_imul = OpVariable %_ptr_uint CrossWorkgroup %imul
@@ -102,6 +113,7 @@
102113
%var_bitand = OpVariable %_ptr_uint CrossWorkgroup %bitand
103114
%var_logor = OpVariable %_ptr_bool CrossWorkgroup %logor
104115
%var_logand = OpVariable %_ptr_bool CrossWorkgroup %logand
116+
%var_lognot = OpVariable %_ptr_bool CrossWorkgroup %lognot
105117

106118
%15 = OpFunction %void Pure %14
107119
%entry = OpLabel

0 commit comments

Comments
 (0)