diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-16 01:09:11 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-16 01:09:11 +0800 |
| commit | 72a559302280a3837efea331829b70d9bb218f7a (patch) | |
| tree | 01345284e79d76b071fed85406e5c983aa413720 /backend/lib/CodeGen/GlobalISel | |
| parent | 94124b0d5604d6d6a6e1b923411e97287fa51e8b (diff) | |
| download | rcc-project-72a559302280a3837efea331829b70d9bb218f7a.tar.gz rcc-project-72a559302280a3837efea331829b70d9bb218f7a.tar.xz | |
[RISCV][GlobalISel] Select constant operands as immediates
Diffstat (limited to 'backend/lib/CodeGen/GlobalISel')
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 642e26f..31d880e 100644 --- a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -2,6 +2,7 @@ #include "rcc/CodeGen/GlobalISel/InstructionSelect.h" +#include "rcc/CodeGen/GlobalISel/Utils.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" #include "rcc/CodeGen/MachineFunctionCloner.h" @@ -240,8 +241,16 @@ Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction for (std::size_t Index = 0; Index < Worklist.size(); ++Index) { MachineInstr *Instruction = Worklist[Index]; - if (Instruction->parent() == nullptr) - return std::unexpected(passFailure("instruction selector lost its input instruction")); + if (Instruction == nullptr || Instruction->parent() == nullptr) + continue; + if (isTriviallyDead(*Instruction, Function.registerInfo(), Target)) { + auto Removed = eraseInstr(*Instruction, Function.registerInfo(), Target); + if (!Removed) + return std::unexpected(Removed.error()); + Result.Changed = true; + Result.Changes.add(MachinePassChange::Instructions); + continue; + } const InstructionDescriptor *CurrentDescriptor = Target.instructionDescriptor(Instruction->opcode()); if (CurrentDescriptor == nullptr) |
