[llvm] [VectorCombine] fold fptoui(fdiv(uitofp(x),uitofp(y))) into udiv(x,y) (PR #214844)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 03:52:00 PDT 2026


================
@@ -2332,6 +2333,90 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
   return true;
 }
 
+/// Try to fold fptoui(fdiv(x,y)) to udiv(x,y), where x & y are either uitofp
+/// instructions or fp-constants that exactly represent integers.
+bool VectorCombine::foldFDivToUDiv(Instruction &I) {
+  const DataLayout &DL = I.getDataLayout();
+  Value *X, *Y;
+  if (!match(&I, m_FPToUI(m_OneUse(m_FDiv(m_Value(X), m_Value(Y))))))
+    return false;
+
+  Type *IntTy = I.getType();
+
+  auto MatchConstOrInst = [&](Value *V) -> Value * {
+    Value *Src;
+    // match uitofp
+    if (match(V, m_OneUse(m_UIToFP(m_Value(Src))))) {
+      if (Src->getType() != IntTy)
----------------
RKSimon wrote:

Is just the round trip type check enough for any int/fp type pair? If so, make sure you (briefly) explain why in the `match uitofp` comment

https://github.com/llvm/llvm-project/pull/214844


More information about the llvm-commits mailing list