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

Yeting Kuo via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 01:01:43 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() &&
----------------
yetingk wrote:

What circumstance that the third operand of ADDI is not an immediate? 

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


More information about the llvm-commits mailing list