[llvm] [RISCV][GISel] Add support for G_IS_FPCLASS in F and D extensions (PR #72000)
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 13:49:32 PST 2023
================
@@ -948,6 +952,56 @@ bool RISCVInstructionSelector::selectFPCompare(MachineInstr &MI,
return true;
}
+bool RISCVInstructionSelector::selectIsFPClass(MachineInstr &MI,
+ MachineIRBuilder &MIB,
+ MachineRegisterInfo &MRI) const {
+ Register GISFPCLASS = MI.getOperand(0).getReg();
+ Register Src = MI.getOperand(1).getReg();
+ const MachineOperand &ImmOp = MI.getOperand(2);
+ const unsigned XLen = STI.getXLen();
+ unsigned NewOpc = MRI.getType(Src).getSizeInBits() == 32 ? RISCV::FCLASS_S
+ : RISCV::FCLASS_D;
+
+ // Turn LLVM IR's floating point classes to that in RISCV,
+ // by simply rotating the 10-bit immediate right by two bits.
+ APInt GFpClassImm(10, static_cast<uint64_t>(ImmOp.getImm()));
+ APInt FClassMask = GFpClassImm.rotr(2).zext(XLen);
+
+ Register FClassResult = MRI.createVirtualRegister(&RISCV::GPRRegClass);
+ // Insert FCLASS_S/D.
+ auto FClass = MIB.buildInstr(NewOpc, {FClassResult}, {Src});
+ if (!FClass.constrainAllUses(TII, TRI, RBI))
+ return false;
+
+ // If there is only a single bit set in the mask, lower to SLLI + SRLI.
+ if (FClassMask.popcount() == 1) {
+ Register SLResult = MRI.createVirtualRegister(&RISCV::GPRRegClass);
+ auto SLLI = MIB.buildInstr(RISCV::SLLI, {SLResult}, {FClassResult})
----------------
mshockwave wrote:
Done
https://github.com/llvm/llvm-project/pull/72000
More information about the llvm-commits
mailing list