[llvm] fc7c706 - ValueTracking: Add cannotBeOrderedLessThanZero to KnownFPClass
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 11:44:45 PDT 2023
Author: Matt Arsenault
Date: 2023-04-13T14:44:34-04:00
New Revision: fc7c706e3f93fa1f700a7ded2ae797aad32d892e
URL: https://github.com/llvm/llvm-project/commit/fc7c706e3f93fa1f700a7ded2ae797aad32d892e
DIFF: https://github.com/llvm/llvm-project/commit/fc7c706e3f93fa1f700a7ded2ae797aad32d892e.diff
LOG: ValueTracking: Add cannotBeOrderedLessThanZero to KnownFPClass
Eventually we should be able to replace the existing
CannotBeOrderedLessThanZero.
Added:
Modified:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index c3093d5209e6..85c6021eea24 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -265,6 +265,19 @@ struct KnownFPClass {
/// floating-point mode for the function interprets denormals as zero.
bool isKnownNeverLogicalZero(const Function &F, Type *Ty) const;
+ /// Return true if we can prove that the analyzed floating-point value is
+ /// either NaN or never less than -0.0.
+ ///
+ /// NaN --> true
+ /// +0 --> true
+ /// -0 --> true
+ /// x > +0 --> true
+ /// x < -0 --> false
+ bool cannotBeOrderedLessThanZero() const {
+ const FPClassTest OrderedNegMask = fcNegSubnormal | fcNegNormal | fcNegInf;
+ return (KnownFPClasses & OrderedNegMask) == fcNone;
+ }
+
KnownFPClass &operator|=(const KnownFPClass &RHS) {
KnownFPClasses = KnownFPClasses | RHS.KnownFPClasses;
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 211959f2895b..9327315304c8 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1616,6 +1616,59 @@ TEST_F(ComputeKnownFPClassTest, FMulNoZero) {
expectKnownFPClass(fcAllFlags, std::nullopt, A7);
}
+TEST_F(ComputeKnownFPClassTest, CannotBeOrderedLessThanZero) {
+ parseAssembly("define float @test(float %arg) {\n"
+ " %A = fmul float %arg, %arg"
+ " ret float %A\n"
+ "}\n");
+
+ Type *FPTy = Type::getDoubleTy(M->getContext());
+ const DataLayout &DL = M->getDataLayout();
+
+ EXPECT_TRUE(
+ computeKnownFPClass(ConstantFP::getZero(FPTy, /*Negative=*/false), DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_TRUE(
+ computeKnownFPClass(ConstantFP::getZero(FPTy, /*Negative=*/true), DL)
+ .cannotBeOrderedLessThanZero());
+
+ EXPECT_TRUE(computeKnownFPClass(ConstantFP::getInfinity(FPTy, false), DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_FALSE(computeKnownFPClass(ConstantFP::getInfinity(FPTy, true), DL)
+ .cannotBeOrderedLessThanZero());
+
+ EXPECT_TRUE(computeKnownFPClass(ConstantFP::get(FPTy, 1.0), DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_FALSE(computeKnownFPClass(ConstantFP::get(FPTy, -1.0), DL)
+ .cannotBeOrderedLessThanZero());
+
+ EXPECT_TRUE(
+ computeKnownFPClass(
+ ConstantFP::get(FPTy, APFloat::getSmallest(FPTy->getFltSemantics(),
+ /*Negative=*/false)),
+ DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_FALSE(
+ computeKnownFPClass(
+ ConstantFP::get(FPTy, APFloat::getSmallest(FPTy->getFltSemantics(),
+ /*Negative=*/true)),
+ DL)
+ .cannotBeOrderedLessThanZero());
+
+ EXPECT_TRUE(
+ computeKnownFPClass(ConstantFP::getQNaN(FPTy, /*Negative=*/false), DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_TRUE(
+ computeKnownFPClass(ConstantFP::getQNaN(FPTy, /*Negative=*/true), DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_TRUE(
+ computeKnownFPClass(ConstantFP::getSNaN(FPTy, /*Negative=*/false), DL)
+ .cannotBeOrderedLessThanZero());
+ EXPECT_TRUE(
+ computeKnownFPClass(ConstantFP::getSNaN(FPTy, /*Negative=*/true), DL)
+ .cannotBeOrderedLessThanZero());
+}
+
TEST_F(ValueTrackingTest, isNonZeroRecurrence) {
parseAssembly(R"(
define i1 @test(i8 %n, i8 %r) {
More information about the llvm-commits
mailing list