-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstSimplify] Only handle canonical forms in simplifyAndOrOfFCmps
. NFC.
#98136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-analysis Author: Yingwei Zheng (dtcxzyw) ChangesThis patch avoids calling Full diff: https://github.com/llvm/llvm-project/pull/98136.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 1b72f151e3692..45d9f45d6f4e4 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1872,14 +1872,11 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
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)))
+ // (fcmp ord X, 0) & (fcmp o** X, Y) --> fcmp o** X, Y
+ // (fcmp uno X, 0) & (fcmp o** X, Y) --> false
+ // (fcmp uno X, 0) | (fcmp u** X, Y) --> fcmp u** X, Y
+ // (fcmp ord X, 0) | (fcmp u** X, Y) --> true
+ if ((LHS0 == RHS0 || LHS0 == RHS1) && match(LHS1, m_PosZeroFP()))
return FCmpInst::isOrdered(PredL) == FCmpInst::isOrdered(PredR)
? static_cast<Value *>(RHS)
: ConstantInt::getBool(LHS->getType(), !IsAnd);
@@ -1888,14 +1885,11 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
if ((PredR == FCmpInst::FCMP_ORD || PredR == FCmpInst::FCMP_UNO) &&
((FCmpInst::isOrdered(PredL) && IsAnd) ||
(FCmpInst::isUnordered(PredL) && !IsAnd))) {
- // (fcmp o** X, Y) & (fcmp ord X, NNAN) --> fcmp o** X, Y
- // (fcmp o** X, Y) & (fcmp uno X, NNAN) --> false
- // (fcmp u** X, Y) | (fcmp uno X, NNAN) --> fcmp u** X, Y
- // (fcmp u** X, Y) | (fcmp ord X, NNAN) --> true
- if (((RHS1 == LHS0 || RHS1 == LHS1) &&
- isKnownNeverNaN(RHS0, /*Depth=*/0, Q)) ||
- ((RHS0 == LHS0 || RHS0 == LHS1) &&
- isKnownNeverNaN(RHS1, /*Depth=*/0, Q)))
+ // (fcmp o** X, Y) & (fcmp ord X, 0) --> fcmp o** X, Y
+ // (fcmp o** X, Y) & (fcmp uno X, 0) --> false
+ // (fcmp u** X, Y) | (fcmp uno X, 0) --> fcmp u** X, Y
+ // (fcmp u** X, Y) | (fcmp ord X, 0) --> true
+ if ((RHS0 == LHS0 || RHS0 == LHS1) && match(RHS1, m_PosZeroFP()))
return FCmpInst::isOrdered(PredL) == FCmpInst::isOrdered(PredR)
? static_cast<Value *>(LHS)
: ConstantInt::getBool(LHS->getType(), !IsAnd);
diff --git a/llvm/test/Transforms/InstSimplify/logic-of-fcmps.ll b/llvm/test/Transforms/InstSimplify/logic-of-fcmps.ll
index 4b2ff1b3d050c..3a8bf53b32cab 100644
--- a/llvm/test/Transforms/InstSimplify/logic-of-fcmps.ll
+++ b/llvm/test/Transforms/InstSimplify/logic-of-fcmps.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
; Cycle through commuted variants where one operand of fcmp ord/uno is
; known not-a-NAN and the other is repeated in the logically-connected fcmp.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
… NFC. (llvm#98136) This patch avoids calling `isKnownNeverNaN` in `simplifyAndOrOfFCmps` since `fcmp ord/uno X, NNAN` will be canonicalized into `fcmp ord/uno X, 0.0` in InstCombine.
This patch avoids calling
isKnownNeverNaN
insimplifyAndOrOfFCmps
sincefcmp ord/uno X, NNAN
will be canonicalized intofcmp ord/uno X, 0.0
in InstCombine.