@@ -1096,6 +1096,26 @@ static bool matchICmpOperand(const APInt *&Offset, Value *LHS, Value *Val,
1096
1096
return false ;
1097
1097
}
1098
1098
1099
+ // / Get value range for a "(Val + Offset) Pred RHS" condition.
1100
+ static ValueLatticeElement getValueFromSimpleICmpCondition (
1101
+ CmpInst::Predicate Pred, Value *RHS, const APInt *Offset) {
1102
+ ConstantRange RHSRange (RHS->getType ()->getIntegerBitWidth (),
1103
+ /* isFullSet=*/ true );
1104
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
1105
+ RHSRange = ConstantRange (CI->getValue ());
1106
+ else if (Instruction *I = dyn_cast<Instruction>(RHS))
1107
+ if (auto *Ranges = I->getMetadata (LLVMContext::MD_range))
1108
+ RHSRange = getConstantRangeFromMetadata (*Ranges);
1109
+
1110
+ ConstantRange TrueValues =
1111
+ ConstantRange::makeAllowedICmpRegion (Pred, RHSRange);
1112
+
1113
+ if (Offset)
1114
+ TrueValues = TrueValues.subtract (*Offset);
1115
+
1116
+ return ValueLatticeElement::getRange (std::move (TrueValues));
1117
+ }
1118
+
1099
1119
static ValueLatticeElement getValueFromICmpCondition (Value *Val, ICmpInst *ICI,
1100
1120
bool isTrueDest) {
1101
1121
Value *LHS = ICI->getOperand (0 );
@@ -1118,30 +1138,14 @@ static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI,
1118
1138
return ValueLatticeElement::getOverdefined ();
1119
1139
1120
1140
const APInt *Offset = nullptr ;
1121
- if (!matchICmpOperand (Offset, LHS, Val, EdgePred)) {
1122
- std::swap (LHS, RHS);
1123
- EdgePred = CmpInst::getSwappedPredicate (EdgePred);
1124
- if (!matchICmpOperand (Offset, LHS, Val, EdgePred))
1125
- return ValueLatticeElement::getOverdefined ();
1126
- }
1127
-
1128
- // Calculate the range of values that are allowed by the comparison.
1129
- ConstantRange RHSRange (RHS->getType ()->getIntegerBitWidth (),
1130
- /* isFullSet=*/ true );
1131
- if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
1132
- RHSRange = ConstantRange (CI->getValue ());
1133
- else if (Instruction *I = dyn_cast<Instruction>(RHS))
1134
- if (auto *Ranges = I->getMetadata (LLVMContext::MD_range))
1135
- RHSRange = getConstantRangeFromMetadata (*Ranges);
1141
+ if (matchICmpOperand (Offset, LHS, Val, EdgePred))
1142
+ return getValueFromSimpleICmpCondition (EdgePred, RHS, Offset);
1136
1143
1137
- // If we're interested in the false dest, invert the condition
1138
- ConstantRange TrueValues =
1139
- ConstantRange::makeAllowedICmpRegion (EdgePred, RHSRange );
1144
+ CmpInst::Predicate SwappedPred = CmpInst::getSwappedPredicate (EdgePred);
1145
+ if ( matchICmpOperand (Offset, RHS, Val, SwappedPred))
1146
+ return getValueFromSimpleICmpCondition (SwappedPred, LHS, Offset );
1140
1147
1141
- if (Offset) // Apply the offset from above.
1142
- TrueValues = TrueValues.subtract (*Offset);
1143
-
1144
- return ValueLatticeElement::getRange (std::move (TrueValues));
1148
+ return ValueLatticeElement::getOverdefined ();
1145
1149
}
1146
1150
1147
1151
// Handle conditions of the form
0 commit comments