[llvm] [X86][GlobalISel] Support fp80 for G_FPTRUNC and G_FPEXT (PR #141611)
Evgenii Kudriashov via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 25 16:50:28 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);
----------------
e-kud wrote:
> The mismatched size case has to be interpreted as G_ANYEXT / G_TRUNC
@arsenm I've returned to this PR. SDAG actually uses `anyext` load and `trunc` store.
```
Combining: t4: f64 = fp_extend t3
Creating new node: t7: f64,ch = load<(load (s32) from %fixed-stack.0), anyext from f32> t0, FrameIndex:i32<-1>, undef:i32
```
And fp_round in selection preprocessor
```
t5: f32 = fp_round t3, TargetConstant:i32<0>
t6: ch = X86ISD::RET_GLUE t0, TargetConstant:i32<0>, t5
===== Instruction selection begins: %bb.0 ''
Creating new node: t8: ch = store<(store (s32) into %stack.0), trunc to f32> t0, t3, FrameIndex:i32<0>, undef:i32
Creating new node: t9: f32,ch = load<(load (s32) from %stack.0)> t8, FrameIndex:i32<0>, undef:i32
```
> not an FP operation.
What if the fp operation indication would be LLT type when floats are finally merged?
https://github.com/llvm/llvm-project/pull/141611
More information about the llvm-commits
mailing list