@@ -875,48 +875,6 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueSelect(
875
875
FalseVal = intersect (FalseVal,
876
876
getValueFromCondition (SI->getFalseValue (), Cond, false ));
877
877
878
- // Handle clamp idioms such as:
879
- // %24 = constantrange<0, 17>
880
- // %39 = icmp eq i32 %24, 0
881
- // %40 = add i32 %24, -1
882
- // %siv.next = select i1 %39, i32 16, i32 %40
883
- // %siv.next = constantrange<0, 17> not <-1, 17>
884
- // In general, this can handle any clamp idiom which tests the edge
885
- // condition via an equality or inequality.
886
- if (auto *ICI = dyn_cast<ICmpInst>(Cond)) {
887
- ICmpInst::Predicate Pred = ICI->getPredicate ();
888
- Value *A = ICI->getOperand (0 );
889
- if (ConstantInt *CIBase = dyn_cast<ConstantInt>(ICI->getOperand (1 ))) {
890
- auto addConstants = [](ConstantInt *A, ConstantInt *B) {
891
- assert (A->getType () == B->getType ());
892
- return ConstantInt::get (A->getType (), A->getValue () + B->getValue ());
893
- };
894
- // See if either input is A + C2, subject to the constraint from the
895
- // condition that A != C when that input is used. We can assume that
896
- // that input doesn't include C + C2.
897
- ConstantInt *CIAdded;
898
- switch (Pred) {
899
- default : break ;
900
- case ICmpInst::ICMP_EQ:
901
- if (match (SI->getFalseValue (), m_Add (m_Specific (A),
902
- m_ConstantInt (CIAdded)))) {
903
- auto ResNot = addConstants (CIBase, CIAdded);
904
- FalseVal = intersect (FalseVal,
905
- ValueLatticeElement::getNot (ResNot));
906
- }
907
- break ;
908
- case ICmpInst::ICMP_NE:
909
- if (match (SI->getTrueValue (), m_Add (m_Specific (A),
910
- m_ConstantInt (CIAdded)))) {
911
- auto ResNot = addConstants (CIBase, CIAdded);
912
- TrueVal = intersect (TrueVal,
913
- ValueLatticeElement::getNot (ResNot));
914
- }
915
- break ;
916
- };
917
- }
918
- }
919
-
920
878
ValueLatticeElement Result = TrueVal;
921
879
Result.mergeIn (FalseVal);
922
880
return Result;
@@ -1089,6 +1047,13 @@ static bool matchICmpOperand(APInt &Offset, Value *LHS, Value *Val,
1089
1047
return true ;
1090
1048
}
1091
1049
1050
+ // Handle the symmetric case. This appears in saturation patterns like
1051
+ // (x == 16) ? 16 : (x + 1).
1052
+ if (match (Val, m_Add (m_Specific (LHS), m_APInt (C)))) {
1053
+ Offset = -*C;
1054
+ return true ;
1055
+ }
1056
+
1092
1057
// If (x | y) < C, then (x < C) && (y < C).
1093
1058
if (match (LHS, m_c_Or (m_Specific (Val), m_Value ())) &&
1094
1059
(Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_ULE))
0 commit comments