-
Notifications
You must be signed in to change notification settings - Fork 14.5k
DAG: Lower fcNormal is.fpclass to compare with inf #100389
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
DAG: Lower fcNormal is.fpclass to compare with inf #100389
Conversation
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-backend-x86 Author: Matt Arsenault (arsenm) ChangesLooks worse for x86 without the fabs check. Not sure if Full diff: https://github.com/llvm/llvm-project/pull/100389.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 0036c182ab9db..4227f7bec9ec8 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -8652,6 +8652,31 @@ SDValue TargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
return DAG.getSetCC(DL, ResultVT, Op, Inf,
IsOrdered ? OrderedCmpOpcode : UnorderedCmpOpcode);
}
+
+ if (FPTestMask == fcNormal) {
+ // TODO: Handle unordered
+ ISD::CondCode IsFiniteOp = IsInvertedFP ? ISD::SETUGE : ISD::SETOLT;
+ ISD::CondCode IsNormalOp = IsInvertedFP ? ISD::SETOLT : ISD::SETUGE;
+
+ if (isCondCodeLegalOrCustom(IsFiniteOp,
+ OperandVT.getScalarType().getSimpleVT()) &&
+ isCondCodeLegalOrCustom(IsNormalOp,
+ OperandVT.getScalarType().getSimpleVT()) &&
+ isFAbsFree(OperandVT)) {
+ // isnormal(x) --> fabs(x) < infinity && !(fabs(x) < smallest_normal)
+ SDValue Inf =
+ DAG.getConstantFP(APFloat::getInf(Semantics), DL, OperandVT);
+ SDValue SmallestNormal = DAG.getConstantFP(
+ APFloat::getSmallestNormalized(Semantics), DL, OperandVT);
+
+ SDValue Abs = DAG.getNode(ISD::FABS, DL, OperandVT, Op);
+ SDValue IsFinite = DAG.getSetCC(DL, ResultVT, Abs, Inf, IsFiniteOp);
+ SDValue IsNormal =
+ DAG.getSetCC(DL, ResultVT, Abs, SmallestNormal, IsNormalOp);
+ unsigned LogicOp = IsInvertedFP ? ISD::OR : ISD::AND;
+ return DAG.getNode(LogicOp, DL, ResultVT, IsFinite, IsNormal);
+ }
+ }
}
// Some checks may be represented as inversion of simpler check, for example
|
Seems unlikely that this would ever be profitable in the ordered case, since you can implement that with pretty simple integer checks on the exponent field. (Check that it isn't 0 and isn't maximal.) |
1b48c68
to
fc46244
Compare
257cb80
to
fcfbc51
Compare
fc46244
to
6226f31
Compare
fcfbc51
to
f515257
Compare
6226f31
to
eaf47a2
Compare
f515257
to
1e2a2b6
Compare
eaf47a2
to
7d48a38
Compare
1e2a2b6
to
f5da092
Compare
7d48a38
to
f4df5b3
Compare
f5da092
to
9061a14
Compare
f4df5b3
to
226d977
Compare
9061a14
to
d51a155
Compare
Looks worse for x86 without the fabs check. Not sure if this is useful for any targets.
d51a155
to
9325186
Compare
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.
ping
test coverage? |
This won't trigger on any target I know of |
So why bother? |
Completeness of inverting the instcombine transform, and I thought it would help but depends |
ping |
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.
No objections
Looks worse for x86 without the fabs check. Not sure if
this is useful for any targets.