diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-09-22 00:42:17 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-21 09:42:17 -0700 |
| commit | 4810dbd49067c5dc03ffeb9f580b83146f66326a (patch) | |
| tree | a2161c7bd5960c5d64c4c553fa39660b99904b1b /source/slang | |
| parent | 65e1a5be6d2c1a470df93eff5dd8cd04589485da (diff) | |
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 <yonghe@outlook.com>
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-ir-fuse-satcoop.cpp | 8 | ||||
| -rw-r--r-- | source/slang/slang-ir-redundancy-removal.cpp | 88 | ||||
| -rw-r--r-- | source/slang/slang-ir.cpp | 93 | ||||
| -rw-r--r-- | source/slang/slang-ir.h | 3 |
4 files changed, 102 insertions, 90 deletions
diff --git a/source/slang/slang-ir-fuse-satcoop.cpp b/source/slang/slang-ir-fuse-satcoop.cpp index e6b3d7f10..3de99b94f 100644 --- a/source/slang/slang-ir-fuse-satcoop.cpp +++ b/source/slang/slang-ir-fuse-satcoop.cpp @@ -61,8 +61,12 @@ static IRInst* floatTogether(IRInst* f, IRInst* g) { SLANG_ASSERT(i); - // If any instruction in x has side effects, we can't reorder things - if(i->mightHaveSideEffects()) + // If the instruction is not movable, then obviously we can't move it. + // + // For a slight optimization: This is actually stricter than we need: + // if `x = p;q` and f and g are movable, then we can safely move f and + // g in and maintain the ordering of p and q + if(!isMovableInst(i)) return nullptr; if(usedByG(i)) diff --git a/source/slang/slang-ir-redundancy-removal.cpp b/source/slang/slang-ir-redundancy-removal.cpp index 5f476188e..42a31ea91 100644 --- a/source/slang/slang-ir-redundancy-removal.cpp +++ b/source/slang/slang-ir-redundancy-removal.cpp @@ -8,94 +8,6 @@ namespace Slang struct RedundancyRemovalContext { RefPtr<IRDominatorTree> dom; - 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_Load: - // Load is generally not movable, an exception is loading a global constant buffer. - if (auto load = as<IRLoad>(inst)) - { - auto addrType = load->getPtr()->getDataType(); - switch (addrType->getOp()) - { - case kIROp_ConstantBufferType: - case kIROp_ParameterBlockType: - return true; - default: - break; - } - } - return false; - default: - return false; - } - } bool tryHoistInstToOuterMostLoop(IRGlobalValueWithCode* func, IRInst* inst) { 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<IRDominatorTree*>(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<IRCall>(inst)); + case kIROp_Load: + // Load is generally not movable, an exception is loading a global constant buffer. + if (auto load = as<IRLoad>(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 diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index 54ef87009..c801f156e 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -2427,6 +2427,9 @@ bool isBuiltin(IRInst* inst); // Get the enclosuing function of an instruction. IRFunc* getParentFunc(IRInst* inst); + // True if moving this inst will not change the semantics of the program +bool isMovableInst(IRInst* inst); + #if SLANG_ENABLE_IR_BREAK_ALLOC uint32_t& _debugGetIRAllocCounter(); #endif |
