[llvm] [RISCV] Implement RISCVInstrInfo::isAddImmediate (PR #72356)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 20:10:13 PST 2023


================
@@ -2438,6 +2438,23 @@ MachineBasicBlock::iterator RISCVInstrInfo::insertOutlinedCall(
   return It;
 }
 
+std::optional<RegImmPair> RISCVInstrInfo::isAddImmediate(const MachineInstr &MI,
+                                                         Register Reg) const {
+  // TODO: Handle cases where Reg is a super- or sub-register of the
+  // destination register.
+  const MachineOperand &Op0 = MI.getOperand(0);
+  if (!Op0.isReg() || Reg != Op0.getReg())
+    return std::nullopt;
+
+  // Don't consider ADDIW as a candidate because the caller may not be aware
+  // of its sign extension behaviour.
+  if (MI.getOpcode() == RISCV::ADDI && MI.getOperand(1).isReg() &&
----------------
topperc wrote:

Do we need to handle the LI case like Mips does in `MipsInstrInfo::describeLoadedValue`? I'm not sure returning X0 as the register is meaningful to the caller of isAddImmediate.

https://github.com/llvm/llvm-project/pull/72356


More information about the llvm-commits mailing list