[llvm] [InstSimplify] Generalize `simplifyAndOrOfFCmps` (PR #81027)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 22:32:56 PST 2024
================
@@ -1853,35 +1853,36 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
return nullptr;
FCmpInst::Predicate PredL = LHS->getPredicate(), PredR = RHS->getPredicate();
- if ((PredL == FCmpInst::FCMP_ORD && PredR == FCmpInst::FCMP_ORD && IsAnd) ||
- (PredL == FCmpInst::FCMP_UNO && PredR == FCmpInst::FCMP_UNO && !IsAnd)) {
- // (fcmp ord NNAN, X) & (fcmp ord X, Y) --> fcmp ord X, Y
- // (fcmp ord NNAN, X) & (fcmp ord Y, X) --> fcmp ord Y, X
- // (fcmp ord X, NNAN) & (fcmp ord X, Y) --> fcmp ord X, Y
- // (fcmp ord X, NNAN) & (fcmp ord Y, X) --> fcmp ord Y, X
- // (fcmp uno NNAN, X) | (fcmp uno X, Y) --> fcmp uno X, Y
- // (fcmp uno NNAN, X) | (fcmp uno Y, X) --> fcmp uno Y, X
- // (fcmp uno X, NNAN) | (fcmp uno X, Y) --> fcmp uno X, Y
- // (fcmp uno X, NNAN) | (fcmp uno Y, X) --> fcmp uno Y, X
+ if ((PredL == FCmpInst::FCMP_ORD || PredL == FCmpInst::FCMP_UNO) &&
+ ((FCmpInst::isOrdered(PredR) && IsAnd) ||
+ (FCmpInst::isUnordered(PredR) && !IsAnd))) {
+ // (fcmp ord X, NNAN) & (fcmp o** X, Y) --> fcmp o** X, Y
+ // (fcmp uno X, NNAN) & (fcmp o** X, Y) --> false
+ // (fcmp uno X, NNAN) | (fcmp u** X, Y) --> fcmp u** X, Y
+ // (fcmp ord X, NNAN) | (fcmp u** X, Y) --> true
if (((LHS1 == RHS0 || LHS1 == RHS1) &&
isKnownNeverNaN(LHS0, /*Depth=*/0, Q)) ||
((LHS0 == RHS0 || LHS0 == RHS1) &&
isKnownNeverNaN(LHS1, /*Depth=*/0, Q)))
- return RHS;
-
- // (fcmp ord X, Y) & (fcmp ord NNAN, X) --> fcmp ord X, Y
- // (fcmp ord Y, X) & (fcmp ord NNAN, X) --> fcmp ord Y, X
- // (fcmp ord X, Y) & (fcmp ord X, NNAN) --> fcmp ord X, Y
- // (fcmp ord Y, X) & (fcmp ord X, NNAN) --> fcmp ord Y, X
- // (fcmp uno X, Y) | (fcmp uno NNAN, X) --> fcmp uno X, Y
- // (fcmp uno Y, X) | (fcmp uno NNAN, X) --> fcmp uno Y, X
- // (fcmp uno X, Y) | (fcmp uno X, NNAN) --> fcmp uno X, Y
- // (fcmp uno Y, X) | (fcmp uno X, NNAN) --> fcmp uno Y, X
+ return FCmpInst::isOrdered(PredL) == FCmpInst::isOrdered(PredR)
+ ? static_cast<Value *>(RHS)
----------------
arsenm wrote:
Don't think you need this cast, and the one below?
https://github.com/llvm/llvm-project/pull/81027
More information about the llvm-commits
mailing list