[llvm] [IndVarSimplify] Ensure fp values can be represented as consecutive integers (PR #166649)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 10 05:28:37 PST 2025
================
@@ -196,6 +196,24 @@ static bool ConvertToSInt(const APFloat &APF, int64_t &IntVal) {
return true;
}
+// Ensure we stay within the bounds of fp values that can be represented as
+// integers without gaps, namely 2^24 and 2^53 for IEEE-754 single and double
+// precision respectively (both on negative and positive side).
+static bool isRepresentableAsExactInteger(ConstantFP *FPVal, int64_t IntVal) {
+ const auto &InitValueFltSema = FPVal->getValueAPF().getSemantics();
+ if (!APFloat::isIEEELikeFP(InitValueFltSema))
+ return false;
+
+ uint64_t InitValuePrecision = APFloat::semanticsPrecision(InitValueFltSema);
+ if (InitValuePrecision >= 64)
+ return false;
+
+ uint64_t InitValueIntegerLimit = 1LL << InitValuePrecision;
+ if (AbsoluteValue(IntVal) >= InitValueIntegerLimit)
+ return false;
+ return true;
----------------
dtcxzyw wrote:
```suggestion
return isUIntN(InitValuePrecision, AbsoluteValue(IntVal));
```
https://github.com/llvm/llvm-project/pull/166649
More information about the llvm-commits
mailing list