[llvm] [InstCombine] Fold fptoui (fdiv (uitofp X), C) to udiv X, C (PR #205853)
Sungbin Jo via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 5 02:26:07 PDT 2026
================
@@ -2507,10 +2507,74 @@ static Instruction *foldFPtoI(Instruction &FI, InstCombiner &IC) {
return nullptr;
}
+/// fpto{u/s}i (fdiv ({u/s}itofp X), C) --> {u/s}div X, C
+///
+/// Given N = integer width, p = FP mantissa width, this is safe if:
+/// Unsigned: C > 0 and N <= p.
+/// Signed: C != 0, N - 1 <= p, and not (X == INT_MIN and C == -1).
+/// Then {u/s}itofp is exact and the rounded quotient never crosses an integer,
+/// i.e. floor(rne_p(X/C)) == floor(X/C).
+///
+/// See #205305 for detailed reasoning.
----------------
goranmoomin wrote:
Done in latest commit.
https://github.com/llvm/llvm-project/pull/205853
More information about the llvm-commits
mailing list