From bd6306cdaa4a49344658bd026721b6532e103d09 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 24 Feb 2023 10:01:47 -0800 Subject: More control flow simplifications. (#2673) * More control flow and Phi param simplifications. * Fix. * Fix gcc error. * Fix. * More IR cleanup. * Fix bug in phi param dce + ifelse simplify. * Propagate and DCE side-effect-free functions. * Enhance CFG simplifcation to remove loops with no side effects. * Fix. * Fixes. * Fix tests. Add [__AlwaysFoldIntoUseSite] for rayPayloadLocation. * More cleanup. * Fixes. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-emit-cpp.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source/slang/slang-emit-cpp.cpp') diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index ba6b26ec6..795ec74b0 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -1557,6 +1557,46 @@ void CPPSourceEmitter::emitGlobalInstImpl(IRInst* inst) } } +bool CPPSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst) +{ + bool result = Super::shouldFoldInstIntoUseSites(inst); + if (!result) + return result; + if (as(inst->getDataType()) || as(inst->getDataType())) + { + // If a vector value is being used in a reshape/cast, + // we should not fold it because the implementation of cast will have multiple references to it. + for (auto use = inst->firstUse; use; use = use->nextUse) + { + switch (use->getUser()->getOp()) + { + case kIROp_MatrixReshape: + case kIROp_VectorReshape: + case kIROp_IntCast: + case kIROp_FloatCast: + case kIROp_CastIntToFloat: + case kIROp_CastFloatToInt: + return false; + default: + break; + } + } + switch (inst->getOp()) + { + case kIROp_MatrixReshape: + case kIROp_VectorReshape: + case kIROp_IntCast: + case kIROp_FloatCast: + case kIROp_CastIntToFloat: + case kIROp_CastFloatToInt: + return false; + default: + break; + } + } + return true; +} + static bool _isExported(IRInst* inst) { for (auto decoration : inst->getDecorations()) -- cgit v1.2.3