From d1d4d2d8761792e401a58adaa9cdab4a30acb43f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 5 Sep 2024 09:40:00 -0400 Subject: [PATCH 1/2] ConstProp: stop pooling inline constants Because we already pooled the _Constants, there's no benefit to also pooling inline constants. the robin map to do so just adds extra overhead for no benefit - drop it. without multiblock, shaves around 2% off node. with multiblock, a bit less than 1% but still a win. Signed-off-by: Alyssa Rosenzweig --- FEXCore/Source/Interface/IR/Passes/ConstProp.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 3640f66d5b..8448cf00b1 100644 --- a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -16,7 +16,6 @@ desc: ConstProp, ZExt elim, const pooling, fcmp reduction, const inlining #include #include #include -#include #include #include @@ -79,15 +78,8 @@ class ConstProp final : public FEXCore::IR::Pass { fextl::unordered_map ConstPool; - // Pool inline constant generation. These are typically very small and pool efficiently. - fextl::robin_map InlineConstantGen; Ref CreateInlineConstant(IREmitter* IREmit, uint64_t Constant) { - const auto it = InlineConstantGen.find(Constant); - if (it != InlineConstantGen.end()) { - return it->second; - } - auto Result = InlineConstantGen.insert_or_assign(Constant, IREmit->_InlineConstant(Constant)); - return Result.first->second; + return IREmit->_InlineConstant(Constant); } bool SupportsTSOImm9 {}; const FEXCore::CPUIDEmu* CPUID; @@ -577,8 +569,6 @@ void ConstProp::ConstantPropagation(IREmitter* IREmit, const IRListView& Current } void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) { - InlineConstantGen.clear(); - for (auto [CodeNode, IROp] : CurrentIR.GetAllCode()) { switch (IROp->Op) { case OP_LSHR: From ac65deed6ccd75d6e2715d255d66cc862594c655 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 5 Sep 2024 09:48:59 -0400 Subject: [PATCH 2/2] ConstProp: drop CreateInlineConstant bit of cleanup Signed-off-by: Alyssa Rosenzweig --- .../Source/Interface/IR/Passes/ConstProp.cpp | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 8448cf00b1..5aaa7e54a6 100644 --- a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -78,9 +78,6 @@ class ConstProp final : public FEXCore::IR::Pass { fextl::unordered_map ConstPool; - Ref CreateInlineConstant(IREmitter* IREmit, uint64_t Constant) { - return IREmit->_InlineConstant(Constant); - } bool SupportsTSOImm9 {}; const FEXCore::CPUIDEmu* CPUID; @@ -104,7 +101,7 @@ class ConstProp final : public FEXCore::IR::Pass { if (IsSIMM9 || IsExtended) { IREmit->SetWriteCursor(IR.GetNode(Offset)); - IREmit->ReplaceNodeArgument(CodeNode, Offset_Index, CreateInlineConstant(IREmit, Imm)); + IREmit->ReplaceNodeArgument(CodeNode, Offset_Index, IREmit->_InlineConstant(Imm)); OffsetScale = 1; } } @@ -586,7 +583,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) Constant2 &= 63; } - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant2)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant2)); } break; } @@ -602,7 +599,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) // constant would be in bounds after the JIT's 24/16 shift. if (ARMEmitter::IsImmAddSub(Constant2) && IROp->Size >= 4) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant2)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant2)); } } else if (IROp->Op == OP_SUBNZCV || IROp->Op == OP_SUBWITHFLAGS || IROp->Op == OP_SUB) { // TODO: Generalize this @@ -610,7 +607,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[0], &Constant1)) { if (Constant1 == 0) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[0])); - IREmit->ReplaceNodeArgument(CodeNode, 0, CreateInlineConstant(IREmit, 0)); + IREmit->ReplaceNodeArgument(CodeNode, 0, IREmit->_InlineConstant(0)); } } } @@ -624,7 +621,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[0], &Constant1)) { if (Constant1 == 0) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[0])); - IREmit->ReplaceNodeArgument(CodeNode, 0, CreateInlineConstant(IREmit, 0)); + IREmit->ReplaceNodeArgument(CodeNode, 0, IREmit->_InlineConstant(0)); } } @@ -635,7 +632,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[0], &Constant1)) { if (Constant1 == 0) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[0])); - IREmit->ReplaceNodeArgument(CodeNode, 0, CreateInlineConstant(IREmit, 0)); + IREmit->ReplaceNodeArgument(CodeNode, 0, IREmit->_InlineConstant(0)); } } @@ -647,7 +644,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[1], &Constant2)) { if (ARMEmitter::IsImmAddSub(Constant2)) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant2)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant2)); } } @@ -655,7 +652,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[0], &Constant1)) { if (Constant1 == 0) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[0])); - IREmit->ReplaceNodeArgument(CodeNode, 0, CreateInlineConstant(IREmit, 0)); + IREmit->ReplaceNodeArgument(CodeNode, 0, IREmit->_InlineConstant(0)); } } break; @@ -665,7 +662,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[1], &Constant1)) { if (IsImmLogical(Constant1, IROp->Size * 8)) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant1)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant1)); } } break; @@ -675,7 +672,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[1], &Constant1)) { if (ARMEmitter::IsImmAddSub(Constant1)) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant1)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant1)); } } @@ -687,8 +684,8 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) (Constant2 == 1 || Constant2 == AllOnes) && Constant3 == 0) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[2])); - IREmit->ReplaceNodeArgument(CodeNode, 2, CreateInlineConstant(IREmit, Constant2)); - IREmit->ReplaceNodeArgument(CodeNode, 3, CreateInlineConstant(IREmit, Constant3)); + IREmit->ReplaceNodeArgument(CodeNode, 2, IREmit->_InlineConstant(Constant2)); + IREmit->ReplaceNodeArgument(CodeNode, 3, IREmit->_InlineConstant(Constant3)); } break; @@ -702,11 +699,11 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) uint64_t Constant1 {}; if (IREmit->IsValueConstant(IROp->Args[1], &Constant1) && Constant1 == 0) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant1)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant1)); if (IREmit->IsValueConstant(IROp->Args[0], &Constant0) && (Constant0 == 1 || Constant0 == AllOnes)) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[0])); - IREmit->ReplaceNodeArgument(CodeNode, 0, CreateInlineConstant(IREmit, Constant0)); + IREmit->ReplaceNodeArgument(CodeNode, 0, IREmit->_InlineConstant(Constant0)); } } @@ -717,7 +714,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[1], &Constant2)) { if (ARMEmitter::IsImmAddSub(Constant2)) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant2)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant2)); } } break; @@ -728,7 +725,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) uint64_t Constant {}; if (IREmit->IsValueConstant(Op->NewRIP, &Constant)) { IREmit->SetWriteCursor(CurrentIR.GetNode(Op->NewRIP)); - IREmit->ReplaceNodeArgument(CodeNode, 0, CreateInlineConstant(IREmit, Constant)); + IREmit->ReplaceNodeArgument(CodeNode, 0, IREmit->_InlineConstant(Constant)); } else { auto NewRIP = IREmit->GetOpHeader(Op->NewRIP); if (NewRIP->Op == OP_ENTRYPOINTOFFSET) { @@ -749,7 +746,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) if (IREmit->IsValueConstant(IROp->Args[1], &Constant2)) { if (IsImmLogical(Constant2, IROp->Size * 8)) { IREmit->SetWriteCursor(CurrentIR.GetNode(IROp->Args[1])); - IREmit->ReplaceNodeArgument(CodeNode, 1, CreateInlineConstant(IREmit, Constant2)); + IREmit->ReplaceNodeArgument(CodeNode, 1, IREmit->_InlineConstant(Constant2)); } } break; @@ -785,7 +782,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) uint64_t Constant {}; if (IREmit->IsValueConstant(Op->Direction, &Constant)) { IREmit->SetWriteCursor(CurrentIR.GetNode(Op->Direction)); - IREmit->ReplaceNodeArgument(CodeNode, Op->Direction_Index, CreateInlineConstant(IREmit, Constant)); + IREmit->ReplaceNodeArgument(CodeNode, Op->Direction_Index, IREmit->_InlineConstant(Constant)); } break; } @@ -795,7 +792,7 @@ void ConstProp::ConstantInlining(IREmitter* IREmit, const IRListView& CurrentIR) uint64_t Constant {}; if (IREmit->IsValueConstant(Op->Direction, &Constant)) { IREmit->SetWriteCursor(CurrentIR.GetNode(Op->Direction)); - IREmit->ReplaceNodeArgument(CodeNode, Op->Direction_Index, CreateInlineConstant(IREmit, Constant)); + IREmit->ReplaceNodeArgument(CodeNode, Op->Direction_Index, IREmit->_InlineConstant(Constant)); } break; }