From e2d73014f19defe9f6f683afcaaa3c39e7c7c53f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 26 Jun 2024 12:05:27 -0400 Subject: [PATCH] ConstProp: fix LSHR constant prop Signed-off-by: Alyssa Rosenzweig --- FEXCore/Source/Interface/IR/Passes/ConstProp.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 205219f37..1a31a53a3 100644 --- a/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -298,8 +298,12 @@ void ConstProp::ConstantPropagation(IREmitter* IREmit, const IRListView& Current if (IREmit->IsValueConstant(IROp->Args[0], &Constant1) && IREmit->IsValueConstant(IROp->Args[1], &Constant2)) { // Shifts mask the shift amount by 63 or 31 depending on operating size; - uint64_t ShiftMask = IROp->Size == 8 ? 63 : 31; - uint64_t NewConstant = (Constant1 >> (Constant2 & ShiftMask)) & getMask(IROp); + // The source is masked, which will produce a correctly masked + // destination. Masking the destination without the source instead will + // right-shift garbage into the upper bits instead of zeroes. + Constant1 &= getMask(IROp); + Constant2 &= (IROp->Size == 8 ? 63 : 31); + uint64_t NewConstant = (Constant1 >> Constant2); IREmit->ReplaceWithConstant(CodeNode, NewConstant); } else if (IREmit->IsValueConstant(IROp->Args[1], &Constant2) && Constant2 == 0) { IREmit->SetWriteCursor(CodeNode);