diff --git a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 4fdffd269..3640f66d5 100644 --- a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -205,7 +205,8 @@ void ConstProp::ConstantPropagation(IREmitter* IREmit, const IRListView& Current uint64_t Constant1 {}; uint64_t Constant2 {}; - if (IREmit->IsValueConstant(IROp->Args[0], &Constant1) && IREmit->IsValueConstant(IROp->Args[1], &Constant2)) { + // Order matter for short circuit evaluation, subsequent ifs read constant2. + if (IREmit->IsValueConstant(IROp->Args[1], &Constant2) && IREmit->IsValueConstant(IROp->Args[0], &Constant1)) { uint64_t NewConstant = (Constant1 & Constant2) & getMask(IROp); IREmit->ReplaceWithConstant(CodeNode, NewConstant); } else if (Constant2 == 1) { @@ -217,7 +218,7 @@ void ConstProp::ConstantPropagation(IREmitter* IREmit, const IRListView& Current Constant2 == 1 && Constant3 == 0) { IREmit->ReplaceAllUsesWith(CodeNode, CurrentIR.GetNode(IROp->Args[0])); } - } else if (IROp->Args[0].ID() == IROp->Args[1].ID()) { + } else if (IROp->Args[0].ID() == IROp->Args[1].ID() || (Constant2 & getMask(IROp)) == getMask(IROp)) { // AND with same value results in original value IREmit->ReplaceAllUsesWith(CodeNode, CurrentIR.GetNode(IROp->Args[0])); }