[llvm] [AMDGPU] Price scalar integer to fp casts by source width and sign (PR #225343)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 04:42:49 PDT 2026


================
@@ -1098,22 +1098,34 @@ InstructionCost GCNTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
   };
 
   if (IsIntToFP) {
-    const unsigned ExtOps = UsesInt64 && SrcBits < 64 ? (IsSigned ? 2 : 1) : 0;
+    // A scalar load of 24, 40, 48 or 56 bits is split and its high part load
+    // extends the source. A constant or invariant load aligned to 4 bytes may
+    // be widened instead and then still needs the extension.
+    const auto *Load =
+        I && Src->isIntegerTy() && I->getOperand(0)->getType() == Src
+            ? dyn_cast<LoadInst>(I->getOperand(0))
+            : nullptr;
+    const bool LoadMayWiden =
+        Load && Load->getAlign() >= Align(4) &&
+        (AMDGPU::isConstantAddressSpace(Load->getPointerAddressSpace()) ||
----------------
MrSidims wrote:

>  I think we can do a better check for this. For one thing, !noclobber works.

AFAIU noclobber only picks SMEM vs VMEM and doesn't widen. As practical effect noclobber load in sitofp_i24_global_align4 would lower to `global_load_sbyte + global_load_ushort` on gfx900 and `s_load_i8 + s_load_u16` on gfx1250, with the sign extension free.

> extended global address space

That adds plain global and AS > 15, and widenLoad widens neither. But isConstantAddressSpace was too broad, fixed.

> a utility for

I can move the widenLoad condition into a helper shared with TTI if you'd like.

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


More information about the llvm-commits mailing list