Skip to content

Commit 8e2db8c

Browse files
committed
Add getValueFromFCmpCondition
1 parent 95a311f commit 8e2db8c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/Analysis/ValueTracking.h"
2424
#include "llvm/IR/AssemblyAnnotationWriter.h"
2525
#include "llvm/IR/CFG.h"
26+
#include "llvm/IR/ConstantFPRange.h"
2627
#include "llvm/IR/ConstantRange.h"
2728
#include "llvm/IR/Constants.h"
2829
#include "llvm/IR/DataLayout.h"
@@ -446,6 +447,9 @@ class LazyValueInfoImpl {
446447
std::optional<ValueLatticeElement>
447448
getValueFromICmpCondition(Value *Val, ICmpInst *ICI, bool isTrueDest,
448449
bool UseBlockValue);
450+
std::optional<ValueLatticeElement>
451+
getValueFromFCmpCondition(Value *Val, FCmpInst *FCI, bool IsTrueDest,
452+
bool UseBlockValue);
449453
ValueLatticeElement getValueFromTrunc(Value *Val, TruncInst *Trunc,
450454
bool IsTrueDest);
451455

@@ -1437,6 +1441,22 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
14371441
return ValueLatticeElement::getOverdefined();
14381442
}
14391443

1444+
std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromFCmpCondition(
1445+
Value *Val, FCmpInst *FCI, bool IsTrueDest, bool UseBlockValue) {
1446+
Value *LHS = FCI->getOperand(0);
1447+
Value *RHS = FCI->getOperand(1);
1448+
1449+
// Get the predicate that must hold along the considered edge.
1450+
CmpInst::Predicate EdgePred =
1451+
IsTrueDest ? FCI->getPredicate() : FCI->getInversePredicate();
1452+
const APFloat *RHSC;
1453+
if (LHS == Val && match(RHS, m_APFloat(RHSC))) {
1454+
if (auto CR = ConstantFPRange::makeExactFCmpRegion(EdgePred, *RHSC))
1455+
return ValueLatticeElement::getFPRange(*CR);
1456+
}
1457+
return ValueLatticeElement::getOverdefined();
1458+
}
1459+
14401460
ValueLatticeElement LazyValueInfoImpl::getValueFromTrunc(Value *Val,
14411461
TruncInst *Trunc,
14421462
bool IsTrueDest) {
@@ -1487,6 +1507,9 @@ LazyValueInfoImpl::getValueFromCondition(Value *Val, Value *Cond,
14871507
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Cond))
14881508
return getValueFromICmpCondition(Val, ICI, IsTrueDest, UseBlockValue);
14891509

1510+
if (FCmpInst *FCI = dyn_cast<FCmpInst>(Cond))
1511+
return getValueFromFCmpCondition(Val, FCI, IsTrueDest, UseBlockValue);
1512+
14901513
if (auto *Trunc = dyn_cast<TruncInst>(Cond))
14911514
return getValueFromTrunc(Val, Trunc, IsTrueDest);
14921515

0 commit comments

Comments
 (0)