diff --git a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 881994be1..272463344 100644 --- a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -194,7 +194,6 @@ public: private: bool HandleConstantPools(IREmitter *IREmit, const IRListView& CurrentIR); - void CodeMotionAroundSelects(IREmitter *IREmit, const IRListView& CurrentIR); void FCMPOptimization(IREmitter *IREmit, const IRListView& CurrentIR); void LoadMemStoreMemImmediatePooling(IREmitter *IREmit, const IRListView& CurrentIR); bool ZextAndMaskingElimination(IREmitter *IREmit, const IRListView& CurrentIR, @@ -267,69 +266,6 @@ bool ConstProp::HandleConstantPools(IREmitter *IREmit, const IRListView& Current return Changed; } -// Code motion around selects -// Moves unary ops that depend on a select before the select, if both inputs are constants -// assumes that unary ops without side effects on constants will be constprop'd -void ConstProp::CodeMotionAroundSelects(IREmitter *IREmit, const IRListView& CurrentIR) { - // Code motion around selects - // Moves unary ops that depend on a select before the select, if both inputs are constants - // assumes that unary ops without side effects on constants will be constprop'd - for (auto [BlockNode, BlockIROp] : CurrentIR.GetBlocks()) { - auto BlockOp = BlockIROp->CW(); - for (auto [UnaryOpNode, UnaryOpHdr] : CurrentIR.GetCode(BlockNode)) { - if (IR::GetArgs(UnaryOpHdr->Op) == 1 && !HasSideEffects(UnaryOpHdr->Op) - && !ImplicitFlagClobber(UnaryOpHdr->Op)) { - // could be moved - auto SelectOpNode = IREmit->UnwrapNode(UnaryOpHdr->Args[0]); - auto SelectOpHdr = IREmit->GetOpHeader(UnaryOpHdr->Args[0]); - auto SelectOp = SelectOpHdr->CW(); - - // the value isn't used after the select otherwise - // make sure the sizes match - if (SelectOpHdr->Size == UnaryOpHdr->Size && SelectOpHdr->Op == OP_SELECT && SelectOpNode->NumUses == 1 - && IREmit->IsValueConstant(SelectOp->TrueVal) - && IREmit->IsValueConstant(SelectOp->FalseVal)) { - - IREmit->SetWriteCursor(IREmit->UnwrapNode(SelectOpNode->Header.Previous)); - - size_t OpSize = FEXCore::IR::GetSize(UnaryOpHdr->Op); - - /// copy for TrueVal /// - auto NewUnaryOp1 = IREmit->AllocateRawOp(OpSize); - - // Copy over the op - memcpy(NewUnaryOp1.first, UnaryOpHdr, OpSize); - - for (int i = 0; i < IR::GetArgs(NewUnaryOp1.first->Op); i++) { - NewUnaryOp1.first->Args[i] = IREmit->WrapNode(IREmit->Invalid()); - } - // Set New Op to operate on the constant - IREmit->ReplaceNodeArgument(NewUnaryOp1, 0, IREmit->UnwrapNode(SelectOp->TrueVal)); - // Make select use the operated constant - IREmit->ReplaceNodeArgument(SelectOpNode, 2, NewUnaryOp1); - - /// copy for FalseVal /// - auto NewUnaryOp2 = IREmit->AllocateRawOp(OpSize); - - // Copy over the op - memcpy(NewUnaryOp2.first, UnaryOpHdr, OpSize); - - for (int i = 0; i < IR::GetArgs(NewUnaryOp2.first->Op); i++) { - NewUnaryOp2.first->Args[i] = IREmit->WrapNode(IREmit->Invalid()); - } - // Set New Op to operate on the constant - IREmit->ReplaceNodeArgument(NewUnaryOp2, 0, IREmit->UnwrapNode(SelectOp->FalseVal)); - // Make select use the operated constant - IREmit->ReplaceNodeArgument(SelectOpNode, 3, NewUnaryOp2); - - // Replace uses of the defuct unary op w/ select - IREmit->ReplaceAllUsesWithRange(UnaryOpNode, SelectOpNode, IREmit->GetIterator(IREmit->WrapNode(UnaryOpNode)), IREmit->GetIterator(BlockOp->Last)); - } - } - } - } -} - void ConstProp::FCMPOptimization(IREmitter *IREmit, const IRListView& CurrentIR) { // Make all FCMPs set no flags for (auto [CodeNode, IROp] : CurrentIR.GetAllCode()) { @@ -1257,7 +1193,6 @@ bool ConstProp::Run(IREmitter *IREmit) { Changed = true; } - CodeMotionAroundSelects(IREmit, CurrentIR); FCMPOptimization(IREmit, CurrentIR); LoadMemStoreMemImmediatePooling(IREmit, CurrentIR);