From 4810dbd49067c5dc03ffeb9f580b83146f66326a Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 22 Sep 2023 00:42:17 +0800 Subject: Do not move movable insts in fuse-satcoop (#3221) * Do not move movable insts in fuse-satcoop * Add case for IRCall in isMovableInst --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index b4a8e6f42..95d6c9e1f 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -8132,6 +8132,99 @@ namespace Slang return static_cast(domTree.get()); } + bool isMovableInst(IRInst* inst) + { + // Don't try to modify hoistable insts, they are already globally deduplicated. + if (getIROpInfo(inst->getOp()).isHoistable()) + return false; + + switch (inst->getOp()) + { + case kIROp_Add: + case kIROp_Sub: + case kIROp_Mul: + case kIROp_FRem: + case kIROp_IRem: + case kIROp_Lsh: + case kIROp_Rsh: + case kIROp_And: + case kIROp_Or: + case kIROp_Not: + case kIROp_Neg: + case kIROp_FieldExtract: + case kIROp_FieldAddress: + case kIROp_GetElement: + case kIROp_GetElementPtr: + case kIROp_UpdateElement: + case kIROp_Specialize: + case kIROp_LookupWitness: + case kIROp_OptionalHasValue: + case kIROp_GetOptionalValue: + case kIROp_MakeOptionalValue: + case kIROp_MakeTuple: + case kIROp_GetTupleElement: + case kIROp_MakeStruct: + case kIROp_MakeArray: + case kIROp_MakeArrayFromElement: + case kIROp_MakeVector: + case kIROp_MakeMatrix: + case kIROp_MakeMatrixFromScalar: + case kIROp_MakeVectorFromScalar: + case kIROp_swizzle: + case kIROp_swizzleSet: + case kIROp_MatrixReshape: + case kIROp_MakeString: + case kIROp_MakeResultError: + case kIROp_MakeResultValue: + case kIROp_GetResultError: + case kIROp_GetResultValue: + case kIROp_CastFloatToInt: + case kIROp_CastIntToFloat: + case kIROp_CastIntToPtr: + case kIROp_CastPtrToBool: + case kIROp_CastPtrToInt: + case kIROp_BitAnd: + case kIROp_BitNot: + case kIROp_BitOr: + case kIROp_BitXor: + case kIROp_BitCast: + case kIROp_IntCast: + case kIROp_FloatCast: + case kIROp_Reinterpret: + case kIROp_Greater: + case kIROp_Less: + case kIROp_Geq: + case kIROp_Leq: + case kIROp_Neq: + case kIROp_Eql: + case kIROp_ExtractExistentialType: + case kIROp_ExtractExistentialValue: + case kIROp_ExtractExistentialWitnessTable: + return true; + case kIROp_Call: + // Similar to the case in IRInst::mightHaveSideEffects, pure + // calls are ok + return isSideEffectFreeFunctionalCall(cast(inst)); + case kIROp_Load: + // Load is generally not movable, an exception is loading a global constant buffer. + if (auto load = as(inst)) + { + auto addrType = load->getPtr()->getDataType(); + switch (addrType->getOp()) + { + case kIROp_ConstantBufferType: + case kIROp_ParameterBlockType: + return true; + default: + break; + } + } + return false; + default: + return false; + } + } + } // namespace Slang #if SLANG_VC -- cgit v1.2.3