File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 5353#include " SPIRVValue.h"
5454
5555#include " llvm/ADT/APInt.h"
56+ #include " llvm/ADT/STLExtras.h"
5657
5758#include < set>
5859#include < unordered_map>
@@ -1444,6 +1445,13 @@ SPIRVValue *SPIRVModuleImpl::addNullConstant(SPIRVType *Ty) {
14441445
14451446SPIRVValue *SPIRVModuleImpl::addCompositeConstant (
14461447 SPIRVType *Ty, const std::vector<SPIRVValue *> &Elements) {
1448+ // Add an OpSpecConstantComposite instead if any of the elements is a
1449+ // SpecConstant.
1450+ if (llvm::any_of (Elements, [](SPIRVValue *V) {
1451+ return isSpecConstantOpCode (V->getOpCode ());
1452+ }))
1453+ return addSpecConstantComposite (Ty, Elements);
1454+
14471455 constexpr int MaxNumElements = MaxWordCount - SPIRVConstantComposite::FixedWC;
14481456 const int NumElements = Elements.size ();
14491457
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ target triple = "spir-unknown-unknown"
3939; CHECK-SPIRV-TYPED-PTR: 7 SpecConstantOp [[AS2]] [[ASTRC:[0-9]+]] 70 [[ASTR]] [[I320]] [[I320]]
4040; CHECK-SPIRV-UNTYPED-PTR: 8 SpecConstantOp [[AS2]] [[ASTRC:[0-9]+]] 4424 [[#]] [[ASTR]] [[I320]] [[I320]]
4141; CHECK-SPIRV: 5 SpecConstantOp [[AS1]] [[I64ARRC:[0-9]+]] 124 [[I64ARR]]
42- ; CHECK-SPIRV: 5 ConstantComposite [[STRUCTTY]] [[STRUCT_INIT:[0-9]+]] [[ASTRC]] [[I64ARRC]]
42+ ; CHECK-SPIRV: 5 SpecConstantComposite [[STRUCTTY]] [[STRUCT_INIT:[0-9]+]] [[ASTRC]] [[I64ARRC]]
4343; CHECK-SPIRV-TYPED-PTR: 5 Variable {{[0-9]+}} [[STRUCT:[0-9]+]] 5 [[STRUCT_INIT]]
4444; CHECK-SPIRV-UNTYPED-PTR: 6 UntypedVariableKHR {{[0-9]+}} [[STRUCT:[0-9]+]] 5 [[STRUCTTY]] [[STRUCT_INIT]]
4545
@@ -49,8 +49,8 @@ target triple = "spir-unknown-unknown"
4949; CHECK-SPIRV-TYPED-PTR: 5 SpecConstantOp [[AS1]] [[STRUCTC:[0-9]+]] 124 [[STRUCT]]
5050; CHECK-SPIRV-TYPED-PTR: 7 SpecConstantOp {{[0-9]+}} [[GEP:[0-9]+]] 67 [[I64ARR]]
5151; CHECK-SPIRV-UNTYPED-PTR: 8 SpecConstantOp {{[0-9]+}} [[GEP:[0-9]+]] 4423 [[#]] [[I64ARR]]
52- ; CHECK-SPIRV-TYPED-PTR: 6 ConstantComposite [[ARRAYTY]] [[ARRAY_INIT:[0-9]+]] [[I64ARRC2]] [[STRUCTC]] [[GEP]]
53- ; CHECK-SPIRV-UNTYPED-PTR: 6 ConstantComposite [[ARRAYTY]] [[ARRAY_INIT:[0-9]+]] [[I64ARRC2]] [[STRUCT]] [[GEP]]
52+ ; CHECK-SPIRV-TYPED-PTR: 6 SpecConstantComposite [[ARRAYTY]] [[ARRAY_INIT:[0-9]+]] [[I64ARRC2]] [[STRUCTC]] [[GEP]]
53+ ; CHECK-SPIRV-UNTYPED-PTR: 6 SpecConstantComposite [[ARRAYTY]] [[ARRAY_INIT:[0-9]+]] [[I64ARRC2]] [[STRUCT]] [[GEP]]
5454; CHECK-SPIRV: 5 Variable {{[0-9]+}} [[ARRAY:[0-9]+]] 5 [[ARRAY_INIT]]
5555
5656; CHECK-LLVM: %structtype = type { ptr addrspace(2), ptr addrspace(1) }
You can’t perform that action at this time.
0 commit comments