Repository navigation
cpu: lower SETP, SETNP, CMOVP and CMOVNP where the reaching PF definition is modeled - #1193
Merged
Merged
Conversation
…tion is modeled The shared lowering now models PF for JP, JNP, SETP, SETNP, CMOVP and CMOVNP outside the x87 profile when every path from the entry reaches the reader through an instruction whose lowering assigns PF: the VEX scalar compares (PF = unordered), PTEST, VPTEST, VTESTPx and PCMPxSTRx (PF cleared), or a register ADD, SUB or CMP that a LAHF reads. A call, a host binding, an undefined PF, any other PF writer, a disagreeing join or an unreached reader is refused (check_parity). Inside the x87 profile check_flags keeps deciding; it now also gates the new readers and counts the VEX compares as producers. cpu_aot_parity compares native and translated readers after VUCOMISS, VCOMISS, VUCOMISD, VCOMISD and FUCOMIP for twelve operand pairs under MXCSR 0x1F80, the equality idiom, SETP after a LAHF source, and faults of CMOVP and CMOVNP memory sources; stale and reversed controls must break and an /O2 build must pass. Three existing refusal cases that pinned SETP or CMOVP as unsupported now insert a PF writer the lowering does not model and expect the PF refusal. Refs R0Y00#1153 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
reviewed
Nov 24, 2026
tedin7
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed 416df060 (diff + Linux doc/bidi checks; Windows build/MASM/MSVC tests and Python checks requiring pefile/iced_x86 were not run locally).
Findings
- Overlap with open PR #1188:
#1188(cpu: lower PF consumers after VEX scalar compares) also targets#1153and modifies the same core files (tools/ffx_version_query.py,tools/x87_lower.py,tests/cpu/x87_compare.py,tests/cpu/x87_parity.py,CMakeLists.txt,docs/experiments.md). Merging either one will require coordinating or rebasing the other. - Code & semantics:
tools/ffx_version_query.py(check_parity): sound forward dataflow overx87_lower._successors(i)starting withknown[entry] = False, intersecting at joins (known[target] and after), resetting toFalseonhost_ops, calls, undefinedPF, or unmodeledPFwriters, and rejecting both unmodeled and unreachablePFreaders.CMOVP/CMOVNPandSETP/SETNPmatch the existingCMOVcc/SETcclowering (including eager evaluation of memory operands and 32-bit zero-extension).tools/x87_lower.py: extendsGATEDwithSETP,SETNP,CMOVP,CMOVNPandassigns_paritywith the four VEX scalar compares so x87-profile functions still go throughcheck_flags.tests/cpu/parity.{asm,def,py}anddocs/experiments.md: title-neutral, include negative controls (stale,reversed) and 5 refusal cases.
Checks run on Linux
python3 -B tests/docs_links_check.py: passed (15 Markdown files, 266 links).python3 -B tests/bidi_controls_check.py: passed (974 tracked files).tests/cpu/integer_flags_check.py,tests/cpu/x87_compare.py,tests/cpu/x87_parity.py: not runnable here becausepefile/iced_x86are not installed in this Linux Python environment.- Windows build/test (
cpu_aot_parity,cl /O2) was not run locally.
This was referenced Nov 24, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1153
What
The shared lowering (
tools/ffx_version_query.py) now lowers SETP, SETNP, CMOVP and CMOVNP, next to JP and JNP, when the reaching PF definition is modeled on every path from the entry (check_parity):lahf_sources).x87_lower.check_flagskeeps deciding.GATEDnow includes the new readers, andassigns_paritycounts the four VEX compares.parity.Existing tests changed (please check)
Three refusal cases pinned "SETP/CMOVP unsupported", which this change lowers on purpose. Each now inserts a PF writer the lowering does not model, so it still tests a refusal, now with the PF message:
tests/cpu/x87_compare.py:fucomi then setp/cmovp→fucomi and inc eax, then setp/cmovp, needle "reads PF, which the integer lowering models only after".tests/cpu/x87_parity.py: "SETP after FUCOMI" → "SETP after FUCOMI and INC", PF needle.tests/cpu/integer_flags_check.py:out_of_scope_setpdrops the LAHF, so SETP reads PF of an ADD that no LAHF reads; needle "reads PF".These adjusted controls found a bug: before
GATEDwas extended, x87 functions skippedcheck_flagsfor SETP and CMOVP.Evidence
cpu_aot_parity(parity.asm, parity.py) runs SETNP, SETP, SETE, SETB, CMOVP (register), CMOVNP (memory) and JP after each VEX compare and after FUCOMIP (x87 profile), for twelve operand pairs: ordered, equal, ±0, infinities, and QNaN and SNaN in either operand. MXCSR is 0x1F80, set and restored by the harness. Native and translated must both match the fixed flags.The test also checks:
setnp; sete; andequality idiom;Two controls must break:
staledrops the compare's PF assignment, andreversedswaps every PF condition. An/O2build must pass.Under masked exceptions VCOMISS and VUCOMISS set the same flags, so this fixture does not tell them apart. FLD quiets a signaling NaN, so the FUCOMIP case compares it as a quiet NaN.
Windows 11 Pro 26100, Intel i7-6820HQ (AVX), MSVC 19.52, commit 416df06 on 645b969:
passes: five refusals; native and lifted match for all exports;
stalefails onpf_ucomiss(qnan, 1)andreversedonpf_ucomiss(1, 2);/O2keeps every rule. The release preset passescpu_aot_parity,cpu_aot_integer_flags,cpu_aot_x87_compareandcpu_aot_x87_parity.The full dev suite without
_hardwarepassed 482/482 before the rebase; after the rebase,ctest --preset dev -R '^cpu_' -E '_hardware$'passes 210/210. Run one at a time,cpu_*_hardwareandcompute_store_aot*_hardwarepass, exceptcpu_shim_shadow_hardware, which already fails on main (reported on #799).tools/form_coverage.py --gaps x64_zen2no longer lists setnp, cmovp or cmovnp.🤖 Generated with Claude Code