[llvm] [X86][GlobalISel] Support fp80 for G_FPTRUNC and G_FPEXT (PR #141611)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 22 09:10:31 PST 2025


================
@@ -8410,6 +8412,33 @@ LegalizerHelper::lowerFPTOINT_SAT(MachineInstr &MI) {
   return Legalized;
 }
 
+// fp conversions using truncating and extending loads and stores.
+LegalizerHelper::LegalizeResult
+LegalizerHelper::lowerFPExtAndTruncMem(MachineInstr &MI) {
+  assert((MI.getOpcode() == TargetOpcode::G_FPEXT ||
+          MI.getOpcode() == TargetOpcode::G_FPTRUNC) &&
+         "Only G_FPEXT and G_FPTRUNC are expected");
+
+  auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
+  MachinePointerInfo PtrInfo;
+  LLT StackTy = MI.getOpcode() == TargetOpcode::G_FPEXT ? SrcTy : DstTy;
+  Align StackTyAlign = getStackTemporaryAlignment(StackTy);
+  auto StackTemp =
+      createStackTemporary(StackTy.getSizeInBytes(), StackTyAlign, PtrInfo);
+
+  MachineFunction &MF = MIRBuilder.getMF();
+  auto *StoreMMO = MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore,
+                                           StackTy, StackTyAlign);
+  MIRBuilder.buildStore(SrcReg, StackTemp, *StoreMMO);
+
+  auto *LoadMMO = MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOLoad,
+                                          StackTy, StackTyAlign);
+  MIRBuilder.buildLoad(DstReg, StackTemp, *LoadMMO);
----------------
arsenm wrote:

I've always found the DAG overloading of extload based on the type to be pretty ill-formed. It's more ill-formed with globalisel. 

Since in SDAG there was only a single load node, with the extension embedded in it, it was more tolerable. Since in globalisel the G_SEXTLOAD and G_ZEXTLOAD have been split out into separate operations, and G_LOAD is inadequate to express the other type of extending operations. Currently G_LOAD is treated as implicitly undef padding the upper bits, in a scalar way. We're lacking an equivalent operation to do elementwise vector extension loads, or elementwise floating-point conversion loads. We do need a G_ANYEXTLOAD and G_FPEXTLOAD 

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


More information about the llvm-commits mailing list