From 08ca43c3c464fe17c5ec42354147197f31356a67 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 14 Jul 2023 18:14:57 -0700 Subject: [PATCH] ConstProp: Fix shift mask in const-prop Noticed while looking at #2700. Testing doesn't currently see this as a bug but will once #2700 starts optimizing StoreRegister+LoadRegister pairs. Doesn't fix the issues in that PR, but this is one. --- External/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/External/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp b/External/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp index 6a22a79a1..d3190336f 100644 --- a/External/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp +++ b/External/FEXCore/Source/Interface/IR/Passes/ConstProp.cpp @@ -732,7 +732,9 @@ bool ConstProp::ConstantPropagation(IREmitter *IREmit, const IRListView& Current if (IREmit->IsValueConstant(Op->Header.Args[0], &Constant1) && IREmit->IsValueConstant(Op->Header.Args[1], &Constant2)) { - uint64_t NewConstant = (Constant1 << Constant2) & getMask(Op); + // 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(Op); IREmit->ReplaceWithConstant(CodeNode, NewConstant); Changed = true; } @@ -758,7 +760,9 @@ bool ConstProp::ConstantPropagation(IREmitter *IREmit, const IRListView& Current if (IREmit->IsValueConstant(Op->Header.Args[0], &Constant1) && IREmit->IsValueConstant(Op->Header.Args[1], &Constant2)) { - uint64_t NewConstant = (Constant1 >> Constant2) & getMask(Op); + // 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(Op); IREmit->ReplaceWithConstant(CodeNode, NewConstant); Changed = true; }