Skip to content

Commit

Permalink
ValueTracking: Use fcAllFlags for unknown value
Browse files Browse the repository at this point in the history
In the failure case we return null, which callers are checking.
We were also returning an fcNone which was unused. It's more
consistent to return fcAllFlags as any possible value, such that
the value is always directly usable without checking the returned
value.
  • Loading branch information
arsenm committed Oct 5, 2023
1 parent 5082e82 commit def3aa4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4003,7 +4003,7 @@ std::pair<Value *, FPClassTest> llvm::fcmpToClassTest(FCmpInst::Predicate Pred,
bool LookThroughSrc) {
const APFloat *ConstRHS;
if (!match(RHS, m_APFloatAllowUndef(ConstRHS)))
return {nullptr, fcNone};
return {nullptr, fcAllFlags};

return fcmpToClassTest(Pred, F, LHS, ConstRHS, LookThroughSrc);
}
Expand All @@ -4025,7 +4025,7 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
// TODO: Handle DAZ by expanding masks to cover subnormal cases.
if (Pred != FCmpInst::FCMP_ORD && Pred != FCmpInst::FCMP_UNO &&
!inputDenormalIsIEEE(F, LHS->getType()))
return {nullptr, fcNone};
return {nullptr, fcAllFlags};

switch (Pred) {
case FCmpInst::FCMP_OEQ: // Match x == 0.0
Expand Down Expand Up @@ -4062,7 +4062,7 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
break;
}

return {nullptr, fcNone};
return {nullptr, fcAllFlags};
}

Value *Src = LHS;
Expand Down Expand Up @@ -4146,7 +4146,7 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
case FCmpInst::FCMP_OGE:
case FCmpInst::FCMP_ULT: {
if (ConstRHS->isNegative()) // TODO
return {nullptr, fcNone};
return {nullptr, fcAllFlags};

// fcmp oge fabs(x), +inf -> fcInf
// fcmp oge x, +inf -> fcPosInf
Expand All @@ -4160,14 +4160,14 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
case FCmpInst::FCMP_OGT:
case FCmpInst::FCMP_ULE: {
if (ConstRHS->isNegative())
return {nullptr, fcNone};
return {nullptr, fcAllFlags};

// No value is ordered and greater than infinity.
Mask = fcNone;
break;
}
default:
return {nullptr, fcNone};
return {nullptr, fcAllFlags};
}
} else if (ConstRHS->isSmallestNormalized() && !ConstRHS->isNegative()) {
// Match pattern that's used in __builtin_isnormal.
Expand Down Expand Up @@ -4196,14 +4196,14 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
break;
}
default:
return {nullptr, fcNone};
return {nullptr, fcAllFlags};
}
} else if (ConstRHS->isNaN()) {
// fcmp o__ x, nan -> false
// fcmp u__ x, nan -> true
Mask = fcNone;
} else
return {nullptr, fcNone};
return {nullptr, fcAllFlags};

// Invert the comparison for the unordered cases.
if (FCmpInst::isUnordered(Pred))
Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1848,13 +1848,13 @@ TEST_F(ComputeKnownFPClassTest, FCmpToClassTest_NInf) {
fcmpToClassTest(CmpInst::FCMP_OGT, *A3->getFunction(), A3->getOperand(0),
A3->getOperand(1));
EXPECT_EQ(nullptr, OgtVal);
EXPECT_EQ(fcNone, OgtClass);
EXPECT_EQ(fcAllFlags, OgtClass);

auto [UleVal, UleClass] =
fcmpToClassTest(CmpInst::FCMP_ULE, *A4->getFunction(), A4->getOperand(0),
A4->getOperand(1));
EXPECT_EQ(nullptr, UleVal);
EXPECT_EQ(fcNone, UleClass);
EXPECT_EQ(fcAllFlags, UleClass);
}

TEST_F(ComputeKnownFPClassTest, FCmpToClassTest_PInf) {
Expand All @@ -1881,13 +1881,13 @@ TEST_F(ComputeKnownFPClassTest, FCmpToClassTest_PInf) {
fcmpToClassTest(CmpInst::FCMP_OLE, *A3->getFunction(), A3->getOperand(0),
A3->getOperand(1));
EXPECT_EQ(nullptr, OleVal);
EXPECT_EQ(fcNone, OleClass);
EXPECT_EQ(fcAllFlags, OleClass);

auto [UgtVal, UgtClass] =
fcmpToClassTest(CmpInst::FCMP_UGT, *A4->getFunction(), A4->getOperand(0),
A4->getOperand(1));
EXPECT_EQ(nullptr, UgtVal);
EXPECT_EQ(fcNone, UgtClass);
EXPECT_EQ(fcAllFlags, UgtClass);
}

TEST_F(ComputeKnownFPClassTest, SqrtNszSignBit) {
Expand Down

0 comments on commit def3aa4

Please sign in to comment.