diff --git a/FEXCore/Source/Interface/IR/IREmitter.h b/FEXCore/Source/Interface/IR/IREmitter.h index d7e90f8c9a..9e991f1dd4 100644 --- a/FEXCore/Source/Interface/IR/IREmitter.h +++ b/FEXCore/Source/Interface/IR/IREmitter.h @@ -245,6 +245,15 @@ class IREmitter { CurrentWriteCursor = Node; } + // Set cursor to write before Node + void SetWriteCursorBefore(OrderedNode* Node) { + auto IR = ViewIR(); + auto Before = IR.at(Node); + --Before; + + SetWriteCursor(std::get<0>(*Before)); + } + OrderedNode* GetWriteCursor() { return CurrentWriteCursor; } diff --git a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 38277b5ae6..d1da68bf74 100644 --- a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -639,10 +639,7 @@ bool ConstProp::ConstantPropagation(IREmitter* IREmit, const IRListView& Current IROp->Op = OP_ADDWITHFLAGS; } - // Set the write cursor to just before this operation. - auto CodeIter = CurrentIR.at(CodeNode); - --CodeIter; - IREmit->SetWriteCursor(std::get<0>(*CodeIter)); + IREmit->SetWriteCursorBefore(CodeNode); // Negate the constant. auto NegConstant = IREmit->_Constant(-Constant2);