[llvm] [X86][GlobalISel] Added support for llvm.get.rounding (PR #147716)
Evgenii Kudriashov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 9 06:06:02 PDT 2025
================
@@ -777,6 +782,82 @@ bool X86LegalizerInfo::legalizeNarrowingStore(MachineInstr &MI,
return true;
}
+bool X86LegalizerInfo::legalizeGETROUNDING(MachineInstr &MI,
+ MachineRegisterInfo &MRI,
+ LegalizerHelper &Helper) const {
+ /*
+ The rounding mode is in bits 11:10 of FPSR, and has the following
+ settings:
+ 00 Round to nearest
+ 01 Round to -inf
+ 10 Round to +inf
+ 11 Round to 0
+
+ GET_ROUNDING, on the other hand, expects the following:
+ -1 Undefined
+ 0 Round to 0
+ 1 Round to nearest
+ 2 Round to +inf
+ 3 Round to -inf
+
+ To perform the conversion, we use a packed lookup table of the four 2-bit
+ values that we can index by FPSP[11:10]
+ 0x2d --> (0b00,10,11,01) --> (0,2,3,1) >> FPSR[11:10]
+
+ (0x2d >> ((FPSR >> 9) & 6)) & 3
+ */
+
+ MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
+ MachineFunction &MF = MIRBuilder.getMF();
+ Register Dst = MI.getOperand(0).getReg();
+ LLT DstTy = MRI.getType(Dst);
+ const LLT s8 = LLT::scalar(8);
+ const LLT s16 = LLT::scalar(16);
+ const LLT s32 = LLT::scalar(32);
+
+ // Save FP Control Word to stack slot
+ int MemSize = 2;
+ Align Alignment = Align(2);
+ MachinePointerInfo PtrInfo;
+ auto StackTemp = Helper.createStackTemporary(TypeSize::getFixed(MemSize),
+ Alignment, PtrInfo);
+ Register StackPtr = StackTemp.getReg(0);
----------------
e-kud wrote:
```suggestion
Register StackPtr = Helper.createStackTemporary(TypeSize::getFixed(MemSize),
Alignment, PtrInfo).getReg(0);
```
I don't see any `StackTemp` usage.
https://github.com/llvm/llvm-project/pull/147716
More information about the llvm-commits
mailing list