aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
index db7ef45..2cceb92 100644
--- a/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
+++ b/backend/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
@@ -1532,7 +1532,22 @@ private:
const std::uint32_t BitWidth = Type->scalarBitWidth();
const std::uint64_t Bits = Floating->Bits.words().empty() ? 0 : Floating->Bits.words().front();
- auto Integer = APInt::fromUnsigned(64, Bits);
+ const InstructionOpcode Move =
+ BitWidth == 32 ? InstructionOpcode::FMV_W_X : InstructionOpcode::FMV_D_X;
+ if (Bits == 0) {
+ auto Zero = physicalRegister(PhysicalRegisterID::X0);
+ if (!Zero)
+ return std::unexpected(Zero.error());
+ auto EraseImmediate = Instruction.eraseOperand(1);
+ if (!EraseImmediate)
+ return std::unexpected(EraseImmediate.error());
+ auto Source = insertPhysicalRegister(Instruction, 1, *Zero, RegisterOperandFlag::Use);
+ if (!Source)
+ return std::unexpected(Source.error());
+ return Instruction.setOpcode(instructionOpcode(Move));
+ }
+
+ auto Integer = APInt::fromUnsigned(BitWidth, Bits);
if (!Integer)
return std::unexpected(Integer.error());
auto IntegerType = LowLevelType::makeCategoryNeutralScalar(64);
@@ -1574,8 +1589,6 @@ private:
constrainBuilderRegisters(Function, Target, {DestinationRegister, *Temporary});
if (!RegisterConstraints)
return std::unexpected(RegisterConstraints.error());
- const InstructionOpcode Move =
- BitWidth == 32 ? InstructionOpcode::FMV_W_X : InstructionOpcode::FMV_D_X;
auto MoveInstruction = Builder.buildInstr(instructionOpcode(Move));
if (!MoveInstruction)
return std::unexpected(MoveInstruction.error());