|
23 | 23 | #include "llvm/Analysis/ValueTracking.h" |
24 | 24 | #include "llvm/IR/AssemblyAnnotationWriter.h" |
25 | 25 | #include "llvm/IR/CFG.h" |
| 26 | +#include "llvm/IR/ConstantFPRange.h" |
26 | 27 | #include "llvm/IR/ConstantRange.h" |
27 | 28 | #include "llvm/IR/Constants.h" |
28 | 29 | #include "llvm/IR/DataLayout.h" |
@@ -446,6 +447,9 @@ class LazyValueInfoImpl { |
446 | 447 | std::optional<ValueLatticeElement> |
447 | 448 | getValueFromICmpCondition(Value *Val, ICmpInst *ICI, bool isTrueDest, |
448 | 449 | bool UseBlockValue); |
| 450 | + std::optional<ValueLatticeElement> |
| 451 | + getValueFromFCmpCondition(Value *Val, FCmpInst *FCI, bool IsTrueDest, |
| 452 | + bool UseBlockValue); |
449 | 453 | ValueLatticeElement getValueFromTrunc(Value *Val, TruncInst *Trunc, |
450 | 454 | bool IsTrueDest); |
451 | 455 |
|
@@ -1437,6 +1441,22 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition( |
1437 | 1441 | return ValueLatticeElement::getOverdefined(); |
1438 | 1442 | } |
1439 | 1443 |
|
| 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 | + |
1440 | 1460 | ValueLatticeElement LazyValueInfoImpl::getValueFromTrunc(Value *Val, |
1441 | 1461 | TruncInst *Trunc, |
1442 | 1462 | bool IsTrueDest) { |
@@ -1487,6 +1507,9 @@ LazyValueInfoImpl::getValueFromCondition(Value *Val, Value *Cond, |
1487 | 1507 | if (ICmpInst *ICI = dyn_cast<ICmpInst>(Cond)) |
1488 | 1508 | return getValueFromICmpCondition(Val, ICI, IsTrueDest, UseBlockValue); |
1489 | 1509 |
|
| 1510 | + if (FCmpInst *FCI = dyn_cast<FCmpInst>(Cond)) |
| 1511 | + return getValueFromFCmpCondition(Val, FCI, IsTrueDest, UseBlockValue); |
| 1512 | + |
1490 | 1513 | if (auto *Trunc = dyn_cast<TruncInst>(Cond)) |
1491 | 1514 | return getValueFromTrunc(Val, Trunc, IsTrueDest); |
1492 | 1515 |
|
|
0 commit comments