x87StackOptimizationPass: Generalize ST(0) tag invalidation on pop

UpdateTopForPop_Slow() now invalidates ST(0)'s tag by default,
so every slow-path StackPop() does this consistently instead of
the previous special case only in OP_POPSTACKDESTROY.

FINCSTP is an exception as it only moves the stack pointer without
invalidating the tag.
This commit is contained in:
Simon Scherer committed 2026-09-03 08:26:14 +02:00
1 parent ca055cd7d5
commit 21b8f8e20d
1 file changed
+7 -6
@@ -272,7 +272,7 @@ private:
Ref LoadStackValueAtOffset_Slow(uint8_t Offset = 0);
void StoreStackValueAtOffset_Slow(Ref Value, uint8_t Offset = 0, bool SetValid = true);
// Update Top value in slow path for a pop
void UpdateTopForPop_Slow();
void UpdateTopForPop_Slow(bool InvalidateTag = true);
void UpdateTopForPush_Slow();
// Synchronizes the current simulated stack with the actual values.
// Returns a new value for Top, that's synchronized between the simulated stack
@@ -573,12 +573,16 @@ void X87StackOptimization::HandleBinopStack(IROps Op64, bool VFOp64, IROps Op80,
HandleBinopValue(Op64, VFOp64, Op80, DestStackOffset, StackOffset2 != DestStackOffset, StackOffset1, StackNode, Reverse);
}
inline void X87StackOptimization::UpdateTopForPop_Slow() {
inline void X87StackOptimization::UpdateTopForPop_Slow(bool InvalidateTag) {
const auto PopContainer = [](auto& container) {
const auto begin = std::begin(container);
std::rotate(begin, std::next(begin), std::end(container));
};
if (InvalidateTag) {
SetX87ValidTag(0, false);
}
// Pop the top of the x87 stack
GetOffsetTopWithCache_Slow(1);
PopContainer(TopOffsetCache);
@@ -1050,9 +1054,6 @@ void X87StackOptimization::Run(IREmitter* Emit) {
break;
}
case OP_POPSTACKDESTROY: {
if (SlowPath) {
SetX87ValidTag(0, false);
}
StackPop();
break;
}
@@ -1178,7 +1179,7 @@ void X87StackOptimization::Run(IREmitter* Emit) {
case OP_INCSTACKTOP: {
if (SlowPath) {
UpdateTopForPop_Slow();
UpdateTopForPop_Slow(false);
} else {
StackData.rotate(false);
}