[llvm] [X86] Faster truncf and roundf on x86 SSE2 (PR #226513)

Divyansh Yadav via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 02:47:16 PDT 2026


================
@@ -3490,6 +3490,14 @@ class LLVM_ABI TargetLoweringBase {
     return false;
   }
 
+  /// Return true if a custom lowered FTRUNC of type VT is cheap enough that it
+  /// is worthwhile to fold an fpto[us]i -> [us]itofp round trip into it. This
+  /// is only queried when FTRUNC is not legal for VT.
+  virtual bool isCustomFTruncCheap(EVT VT) const {
+    assert(VT.isFloatingPoint());
+    return true;
+  }
----------------
schizophrenicmaniac wrote:

Thanks, agreed. I've dropped the new hook and switched to the existing `isTypeDesirableForOp`: `foldFPToIntToFP` now also bails out when `!TLI.isTypeDesirableForOp(ISD::FTRUNC, VT)`, and X86's override returns `false` for `ISD::FTRUNC` without SSE4.1, since there FTRUNC is the conversion round trip plus range check and select. The default implementation only checks `isTypeLegal`, so other targets (including the AArch64 SVE and AMDGPU cases from #198477) are unaffected. The `isint.ll` / `ftrunc.ll` / `unpredictable-brcond.ll` checks still match main. Let me know if you had a different hook in mind.


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


More information about the llvm-commits mailing list