From 082c48d96c5f8f6b4f560d705fe731da14409cb4 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 29 Mar 2023 17:05:07 -0700 Subject: 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 --- source/slang/slang-ir.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'source/slang/slang-ir.cpp') 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(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 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 and an array are + // treated as distinct types. + if (operandCount < 2) break; + auto elementCount = operands[1]; + if (elementCount->getFullType() && elementCount->getFullType()->getOp() != kIROp_IntType) + { + auto intLit = as(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, -- cgit v1.2.3