Repository navigation
[InstCombine] Simplify and correct folding fcmps with the same children - #9120
Open
Steven Perron (s-perron) wants to merge 1 commit into
Open
Steven Perron (s-perron) wants to merge 1 commit into
Steven Perron (s-perron) wants to merge 1 commit into
Conversation
getFCmpCode encoded FCMP_ORD as 0, causing FoldOrOfFCmps to miscompile (fcmp ord x, y) | (fcmp oeq x, y) into (fcmp oeq x, y). Encode fcmp predicates directly using their 4-bit ULGE mask so FoldAndOfFCmps and FoldOrOfFCmps fold bitwise combinations of predicates soundly, including constant true and false results. Backports llvm/llvm-project@aec68b263dc1 (D21775).
Steven Perron (s-perron)
requested review from
Chris B (llvm-beanz) and
Natalie Chouinard (sudonatalie)
November 13, 2026 18:36
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The user-visible floating-point comparison miscompile fix is missing the required entry under Upcoming Release → Bug Fixes in docs/ReleaseNotes.md.
1 open issue
What changed in this PR
Backports LLVM D21775 to fix incorrect InstCombine folding of floating-point comparisons with matching or swapped operands, including the ord | oeq miscompile.
Changes:
- Uses four-bit predicate masks to simplify AND/OR folding and produce constant results where appropriate.
- Adds five regression tests covering matching operands, swapped operands, and constant results.
- Documents InstCombine’s dependency on floating-point predicate bit patterns.
| File | Description |
|---|---|
tools/clang/test/DXC/Passes/InstructionCombining/and-or-fcmp.ll |
Adds regression coverage for comparison folding. |
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp |
Replaces special-case folding with four-bit predicate operations. |
include/llvm/IR/InstrTypes.h |
Documents the dependency on predicate enum bit patterns. |
Review effort: Balanced
Comment on lines
+2023
to
+2025
| if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) | ||
| return getFCmpValue(getFCmpCode(Op0CC) | getFCmpCode(Op1CC), Op0LHS, Op0RHS, | ||
| Builder); |
This branch has not been deployed
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.

getFCmpCode encoded FCMP_ORD as 0, causing FoldOrOfFCmps to miscompile
(fcmp ord x, y) | (fcmp oeq x, y) into (fcmp oeq x, y). Encode fcmp
predicates directly using their 4-bit ULGE mask so FoldAndOfFCmps and
FoldOrOfFCmps fold bitwise combinations of predicates soundly, including
constant true and false results.
Backports llvm/llvm-project@aec68b263dc1 (D21775).