[llvm] [IndVarSimplify] Ensure fp values can be represented as consecutive integers (PR #166649)
Andrew Pinski via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 5 17:01:19 PST 2025
================
@@ -265,6 +280,18 @@ bool IndVarSimplify::handleFloatingPointIV(Loop *L, PHINode *PN) {
!ConvertToSInt(ExitValueVal->getValueAPF(), ExitValue))
return false;
+ const auto &EVFltSema = ExitValueVal->getValueAPF().getSemantics();
+ if (!APFloat::isIEEELikeFP(EVFltSema))
+ return false;
+
+ uint64_t ExitValPrecision = APFloat::semanticsPrecision(EVFltSema);
+ if (ExitValPrecision >= 64)
+ return false;
+
+ uint64_t ExitValIntegerLimit = 1LL << ExitValPrecision;
+ if (uint64_t(std::abs(ExitValue)) > ExitValIntegerLimit)
----------------
pinskia wrote:
Can ExitValue be INT64_MIN ? If so then there would be undefined behavior here. I don't think it can be but it definitely deserves a comment.
https://github.com/llvm/llvm-project/pull/166649
More information about the llvm-commits
mailing list