[llvm] [InstCombine] Fold fptoui(fadd(uitofp(X), C)) to X (PR #210588)
Lucas Ly Ba via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 19 16:38:29 PDT 2026
================
@@ -2581,10 +2580,58 @@ static Instruction *foldFPtoI(Instruction &FI, InstCombiner &IC) {
: BinaryOperator::CreateUDiv(X, C);
}
+// fptoui (fadd (uitofp X), C) --> X
+//
+// X is already an integer, so if 0 <= C < 1 and X fits exactly in the float,
+// adding C can't reach the next integer and fptoui just gives X back. This is
+// the (unsigned)((float)x + 0.5f) rounding trick.
+static Value *foldFPToUIOfUIToFPInc(FPToUIInst &FI) {
+ Value *X;
+ const APFloat *C;
+ if (!match(FI.getOperand(0), m_FAdd(m_UIToFP(m_Value(X)), m_APFloat(C))))
----------------
lucasly-ba wrote:
yes fixed it !
https://github.com/llvm/llvm-project/pull/210588
More information about the llvm-commits
mailing list