diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-29 17:05:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-29 17:05:07 -0700 |
| commit | 082c48d96c5f8f6b4f560d705fe731da14409cb4 (patch) | |
| tree | fe9860aea3326cd321365bc5530a917fcef94718 /source/slang/slang-ir.cpp | |
| parent | a862f5b7007ef50b5def30506f0cea138b73c710 (diff) | |
Update checkpoint policy to make obvious recompute decisions. (#2753)
* Update checkpoint policy to make obvious recompute decisions.
Also adds an optimization to fold updateElement chains on the same array or struct into a single makeArray or makeStruct.
* Bug fixes around array types with different int typed count.
* change test.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index a4d7840d3..16926a742 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2389,6 +2389,25 @@ namespace Slang capabilitySetType, kIROp_CapabilitySet, args.getCount(), args.getBuffer()); } + static void canonicalizeInstOperands(IRBuilder& builder, IRInst* inst) + { + // For Array types, we always want to make sure its element count + // has an int32_t type. We will convert all other int types to int32_t + // to avoid things like float[8] and float[8U] being distinct types. + if (inst->getOp() == kIROp_ArrayType) + { + IRInst* elementCount = inst->getOperand(1); + if (auto intLit = as<IRIntLit>(elementCount)) + { + if (intLit->getDataType()->getOp() != kIROp_IntType) + { + IRInst* newElementCount = builder.getIntValue(builder.getIntType(), intLit->getValue()); + inst->getOperands()[1].usedValue = newElementCount; + } + } + } + } + IRInst* IRBuilder::_findOrEmitHoistableInst( IRType* type, IROp op, @@ -2448,6 +2467,8 @@ namespace Slang } } + canonicalizeInstOperands(*this, inst); + // Find or add the key/inst { IRInstKey key = { inst }; @@ -2515,6 +2536,38 @@ namespace Slang UInt operandCount, IRInst* const* operands) { + switch (op) + { + case kIROp_ArrayType: + { + ShortList<IRInst*, 2> newOperands; + newOperands.addRange(operands, operandCount); + + // If elementCount does not have int type, then we always cast + // it to an int type, to avoid having to deal with the + // possibility that an array<int, 2> and an array<int, 2U> are + // treated as distinct types. + if (operandCount < 2) break; + auto elementCount = operands[1]; + if (elementCount->getFullType() && elementCount->getFullType()->getOp() != kIROp_IntType) + { + auto intLit = as<IRIntLit>(elementCount); + if (intLit) + elementCount = getIntValue(getIntType(), intLit->getValue()); + else + elementCount = emitIntrinsicInst(getIntType(), kIROp_IntCast, 1, &elementCount); + } + newOperands[1] = elementCount; + return (IRType*)createIntrinsicInst( + nullptr, + op, + operandCount, + newOperands.getArrayView().getBuffer()); + } + default: + break; + } + return (IRType*)createIntrinsicInst( nullptr, op, |
