[llvm] [InstCombine] Optimize fcmp ord/uno logical select operations using freeze (PR #205076)
SUBASH BOOPATHI via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 27 03:19:04 PDT 2026
================
@@ -1486,7 +1483,10 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS,
// Ignore the constants because they are obviously not NANs:
// (fcmp ord x, 0.0) & (fcmp ord y, 0.0) -> (fcmp ord x, y)
// (fcmp uno x, 0.0) | (fcmp uno y, 0.0) -> (fcmp uno x, y)
- return Builder.CreateFCmpFMF(PredL, LHS0, RHS0,
+ Value *Y = RHS0;
+ if (IsLogicalSelect)
+ Y = Builder.CreateFreeze(Y, Y->getName() + ".fr");
+ return Builder.CreateFCmpFMF(PredL, LHS0, Y,
----------------
SubashBoopathi1605 wrote:
You are correct @dtcxzyw . I have updated the pull request to clear the nnan and ninf flags when the select is logical. This is because the second operand is only conditionally evaluated in the source, so propagating these flags would make the target more poisonous if the frozen second operand is poison (which can freeze to infinity or NaN).
https://github.com/llvm/llvm-project/pull/205076
More information about the llvm-commits
mailing list