@@ -83,57 +83,6 @@ static bool hasSingleValue(const ValueLatticeElement &Val) {
83
83
return false ;
84
84
}
85
85
86
- // / Combine two sets of facts about the same value into a single set of
87
- // / facts. Note that this method is not suitable for merging facts along
88
- // / different paths in a CFG; that's what the mergeIn function is for. This
89
- // / is for merging facts gathered about the same value at the same location
90
- // / through two independent means.
91
- // / Notes:
92
- // / * This method does not promise to return the most precise possible lattice
93
- // / value implied by A and B. It is allowed to return any lattice element
94
- // / which is at least as strong as *either* A or B (unless our facts
95
- // / conflict, see below).
96
- // / * Due to unreachable code, the intersection of two lattice values could be
97
- // / contradictory. If this happens, we return some valid lattice value so as
98
- // / not confuse the rest of LVI. Ideally, we'd always return Undefined, but
99
- // / we do not make this guarantee. TODO: This would be a useful enhancement.
100
- static ValueLatticeElement intersect (const ValueLatticeElement &A,
101
- const ValueLatticeElement &B) {
102
- // Undefined is the strongest state. It means the value is known to be along
103
- // an unreachable path.
104
- if (A.isUnknown ())
105
- return A;
106
- if (B.isUnknown ())
107
- return B;
108
-
109
- // If we gave up for one, but got a useable fact from the other, use it.
110
- if (A.isOverdefined ())
111
- return B;
112
- if (B.isOverdefined ())
113
- return A;
114
-
115
- // Can't get any more precise than constants.
116
- if (hasSingleValue (A))
117
- return A;
118
- if (hasSingleValue (B))
119
- return B;
120
-
121
- // Could be either constant range or not constant here.
122
- if (!A.isConstantRange () || !B.isConstantRange ()) {
123
- // TODO: Arbitrary choice, could be improved
124
- return A;
125
- }
126
-
127
- // Intersect two constant ranges
128
- ConstantRange Range =
129
- A.getConstantRange ().intersectWith (B.getConstantRange ());
130
- // Note: An empty range is implicitly converted to unknown or undef depending
131
- // on MayIncludeUndef internally.
132
- return ValueLatticeElement::getRange (
133
- std::move (Range), /* MayIncludeUndef=*/ A.isConstantRangeIncludingUndef () ||
134
- B.isConstantRangeIncludingUndef ());
135
- }
136
-
137
86
// ===----------------------------------------------------------------------===//
138
87
// LazyValueInfoCache Decl
139
88
// ===----------------------------------------------------------------------===//
@@ -812,9 +761,9 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
812
761
if (I->getParent () != BB || !isValidAssumeForContext (I, BBI))
813
762
continue ;
814
763
815
- BBLV = intersect (BBLV, *getValueFromCondition (Val, I->getArgOperand (0 ),
816
- /* IsTrueDest*/ true ,
817
- /* UseBlockValue*/ false ));
764
+ BBLV = BBLV. intersect (*getValueFromCondition (Val, I->getArgOperand (0 ),
765
+ /* IsTrueDest*/ true ,
766
+ /* UseBlockValue*/ false ));
818
767
}
819
768
820
769
// If guards are not used in the module, don't spend time looking for them
@@ -824,9 +773,9 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
824
773
make_range (std::next (BBI->getIterator ().getReverse ()), BB->rend ())) {
825
774
Value *Cond = nullptr ;
826
775
if (match (&I, m_Intrinsic<Intrinsic::experimental_guard>(m_Value (Cond))))
827
- BBLV = intersect (BBLV ,
828
- * getValueFromCondition (Val, Cond, /* IsTrueDest*/ true ,
829
- /* UseBlockValue*/ false ));
776
+ BBLV = BBLV. intersect (* getValueFromCondition (Val, Cond ,
777
+ /* IsTrueDest*/ true ,
778
+ /* UseBlockValue*/ false ));
830
779
}
831
780
}
832
781
@@ -913,13 +862,13 @@ LazyValueInfoImpl::solveBlockValueSelect(SelectInst *SI, BasicBlock *BB) {
913
862
// the select condition.
914
863
if (isGuaranteedNotToBeUndef (Cond, AC)) {
915
864
TrueVal =
916
- intersect (TrueVal, *getValueFromCondition (SI->getTrueValue (), Cond,
917
- /* IsTrueDest*/ true ,
918
- /* UseBlockValue*/ false ));
865
+ TrueVal. intersect (*getValueFromCondition (SI->getTrueValue (), Cond,
866
+ /* IsTrueDest*/ true ,
867
+ /* UseBlockValue*/ false ));
919
868
FalseVal =
920
- intersect (FalseVal, *getValueFromCondition (SI->getFalseValue (), Cond,
921
- /* IsTrueDest*/ false ,
922
- /* UseBlockValue*/ false ));
869
+ FalseVal. intersect (*getValueFromCondition (SI->getFalseValue (), Cond,
870
+ /* IsTrueDest*/ false ,
871
+ /* UseBlockValue*/ false ));
923
872
}
924
873
925
874
ValueLatticeElement Result = TrueVal;
@@ -1037,9 +986,9 @@ LazyValueInfoImpl::solveBlockValueIntrinsic(IntrinsicInst *II, BasicBlock *BB) {
1037
986
OpRanges.push_back (*Range);
1038
987
}
1039
988
1040
- return intersect ( ValueLatticeElement::getRange ( ConstantRange::intrinsic (
1041
- II->getIntrinsicID (), OpRanges)),
1042
- MetadataVal);
989
+ return ValueLatticeElement::getRange (
990
+ ConstantRange::intrinsic ( II->getIntrinsicID (), OpRanges))
991
+ . intersect ( MetadataVal);
1043
992
}
1044
993
1045
994
std::optional<ValueLatticeElement>
@@ -1310,7 +1259,7 @@ LazyValueInfoImpl::getValueFromCondition(Value *Val, Value *Cond,
1310
1259
return *LV;
1311
1260
}
1312
1261
1313
- return intersect (*LV, *RV);
1262
+ return LV-> intersect (*RV);
1314
1263
}
1315
1264
1316
1265
// Return true if Usr has Op as an operand, otherwise false.
@@ -1522,7 +1471,7 @@ LazyValueInfoImpl::getEdgeValue(Value *Val, BasicBlock *BBFrom,
1522
1471
// but then the result is not cached.
1523
1472
intersectAssumeOrGuardBlockValueConstantRange (Val, InBlock, CxtI);
1524
1473
1525
- return intersect (*LocalResult, InBlock);
1474
+ return LocalResult-> intersect (InBlock);
1526
1475
}
1527
1476
1528
1477
ValueLatticeElement LazyValueInfoImpl::getValueInBlock (Value *V, BasicBlock *BB,
@@ -1612,7 +1561,7 @@ ValueLatticeElement LazyValueInfoImpl::getValueAtUse(const Use &U) {
1612
1561
PHI->getParent (), /* UseBlockValue*/ false );
1613
1562
}
1614
1563
if (CondVal)
1615
- VL = intersect (VL, *CondVal);
1564
+ VL = VL. intersect (*CondVal);
1616
1565
1617
1566
// Only follow one-use chain, to allow direct intersection of conditions.
1618
1567
// If there are multiple uses, we would have to intersect with the union of
0 commit comments