Improve x86 flag lifting semantics#8300
Open
zznop wants to merge 1 commit into
Open
Conversation
emesare
reviewed
Jun 30, 2026
Expand x86 LLIL flag modeling for arithmetic, test, rotate, shift, double-shift, and signed multiply instructions. Add popcnt-based parity calculation, auxiliary-carry formulas, SBB/ADC carry and overflow handling, IMUL truncation checks, and count-sensitive CF/OF behavior for shifts and rotates. Use LLIL unknown for architecturally undefined flags. Fix several flag correctness issues, including PTEST/VPTEST flag polarity and cleared flags, CCMP/CTEST signed-not-less conditions, EVEX default flag values, and SHLD/SHRD count/result flag behavior. Keep variable-count register shift and rotate value lifts clean by moving count-zero/count-one flag handling into flag callbacks, while preserving count-zero no-op behavior for memory destinations. Also improve ENTER lifting for nonzero nesting levels.
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.
Summary
This improves x86 LLIL flag lifting coverage and correctness across arithmetic, test, rotate, shift, double-shift, and signed multiply instructions. It replaces previously unimplemented or ad hoc flag behavior with proper flag-system callbacks where possible, using newer LLIL operations such as
POPCNT(for PF) andUnknown(to model flags that are expectedly undefined).Changes
POPCNT.LLIL_UNKNOWN.ADCSBBIMULROL/RORRCL/RCRSHL/SALSHRSARSHLDSHRD0preserves destination/flags1uses defined OF behavior0PTEST/VPTEST:SetFlagwritesCCMPNL/CTESTNLnow use signed greater-or-equalSHLD/SHRDissues:ENTERlifting for nonzero nesting levels by emitting the frame pointer display setup described by the instruction semantics.Testing
I've constructed the attached binary that contains each affected instruction along with
lahfandsetoto ensure that flags are consumed and emitted during lifting for observation. I've also tested with other binaries shared by users.x86_flag_lift_variants.zip
Closes #4044