Skip to content

Commit def3aa4

Browse files
committed
ValueTracking: Use fcAllFlags for unknown value
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.
1 parent 5082e82 commit def3aa4

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

llvm/lib/Analysis/ValueTracking.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -4003,7 +4003,7 @@ std::pair<Value *, FPClassTest> llvm::fcmpToClassTest(FCmpInst::Predicate Pred,
40034003
bool LookThroughSrc) {
40044004
const APFloat *ConstRHS;
40054005
if (!match(RHS, m_APFloatAllowUndef(ConstRHS)))
4006-
return {nullptr, fcNone};
4006+
return {nullptr, fcAllFlags};
40074007

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

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

4065-
return {nullptr, fcNone};
4065+
return {nullptr, fcAllFlags};
40664066
}
40674067

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

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

41654165
// No value is ordered and greater than infinity.
41664166
Mask = fcNone;
41674167
break;
41684168
}
41694169
default:
4170-
return {nullptr, fcNone};
4170+
return {nullptr, fcAllFlags};
41714171
}
41724172
} else if (ConstRHS->isSmallestNormalized() && !ConstRHS->isNegative()) {
41734173
// Match pattern that's used in __builtin_isnormal.
@@ -4196,14 +4196,14 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
41964196
break;
41974197
}
41984198
default:
4199-
return {nullptr, fcNone};
4199+
return {nullptr, fcAllFlags};
42004200
}
42014201
} else if (ConstRHS->isNaN()) {
42024202
// fcmp o__ x, nan -> false
42034203
// fcmp u__ x, nan -> true
42044204
Mask = fcNone;
42054205
} else
4206-
return {nullptr, fcNone};
4206+
return {nullptr, fcAllFlags};
42074207

42084208
// Invert the comparison for the unordered cases.
42094209
if (FCmpInst::isUnordered(Pred))

llvm/unittests/Analysis/ValueTrackingTest.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1848,13 +1848,13 @@ TEST_F(ComputeKnownFPClassTest, FCmpToClassTest_NInf) {
18481848
fcmpToClassTest(CmpInst::FCMP_OGT, *A3->getFunction(), A3->getOperand(0),
18491849
A3->getOperand(1));
18501850
EXPECT_EQ(nullptr, OgtVal);
1851-
EXPECT_EQ(fcNone, OgtClass);
1851+
EXPECT_EQ(fcAllFlags, OgtClass);
18521852

18531853
auto [UleVal, UleClass] =
18541854
fcmpToClassTest(CmpInst::FCMP_ULE, *A4->getFunction(), A4->getOperand(0),
18551855
A4->getOperand(1));
18561856
EXPECT_EQ(nullptr, UleVal);
1857-
EXPECT_EQ(fcNone, UleClass);
1857+
EXPECT_EQ(fcAllFlags, UleClass);
18581858
}
18591859

18601860
TEST_F(ComputeKnownFPClassTest, FCmpToClassTest_PInf) {
@@ -1881,13 +1881,13 @@ TEST_F(ComputeKnownFPClassTest, FCmpToClassTest_PInf) {
18811881
fcmpToClassTest(CmpInst::FCMP_OLE, *A3->getFunction(), A3->getOperand(0),
18821882
A3->getOperand(1));
18831883
EXPECT_EQ(nullptr, OleVal);
1884-
EXPECT_EQ(fcNone, OleClass);
1884+
EXPECT_EQ(fcAllFlags, OleClass);
18851885

18861886
auto [UgtVal, UgtClass] =
18871887
fcmpToClassTest(CmpInst::FCMP_UGT, *A4->getFunction(), A4->getOperand(0),
18881888
A4->getOperand(1));
18891889
EXPECT_EQ(nullptr, UgtVal);
1890-
EXPECT_EQ(fcNone, UgtClass);
1890+
EXPECT_EQ(fcAllFlags, UgtClass);
18911891
}
18921892

18931893
TEST_F(ComputeKnownFPClassTest, SqrtNszSignBit) {

0 commit comments

Comments
 (0)