[llvm] [RISCV] Reduce code duplication in RISCVMoveMerge::findMatchingInst. NFCI (PR #154451)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 19 18:06:32 PDT 2025
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/154451
None
>From 8a6450fdf69b90029319e3d436bf7919386e1270 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 19 Aug 2025 18:05:24 -0700
Subject: [PATCH] [RISCV] Reduce code duplication in
RISCVMoveMerge::findMatchingInst. NFCI
---
llvm/lib/Target/RISCV/RISCVMoveMerger.cpp | 25 +++++++++--------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVMoveMerger.cpp b/llvm/lib/Target/RISCV/RISCVMoveMerger.cpp
index d234dcf109d6a..ae311db443bf7 100644
--- a/llvm/lib/Target/RISCV/RISCVMoveMerger.cpp
+++ b/llvm/lib/Target/RISCV/RISCVMoveMerger.cpp
@@ -176,25 +176,20 @@ RISCVMoveMerge::findMatchingInst(MachineBasicBlock::iterator &MBBI,
Register SourceReg = SecondPair->Source->getReg();
Register DestReg = SecondPair->Destination->getReg();
- if (MoveFromSToA && isCandidateToMergeMVA01S(*SecondPair)) {
- // If register pair is valid and destination registers are different.
- if ((RegPair.Destination->getReg() == DestReg))
+ bool IsCandidate = MoveFromSToA ? isCandidateToMergeMVA01S(*SecondPair)
+ : isCandidateToMergeMVSA01(*SecondPair);
+ if (IsCandidate) {
+ // Second destination must be different.
+ if (RegPair.Destination->getReg() == DestReg)
return E;
- // If paired destination register was modified or used, the source reg
- // was modified, there is no possibility of finding matching
- // instruction so exit early.
- if (!ModifiedRegUnits.available(DestReg) ||
- !UsedRegUnits.available(DestReg) ||
- !ModifiedRegUnits.available(SourceReg))
- return E;
-
- return I;
- } else if (!MoveFromSToA && isCandidateToMergeMVSA01(*SecondPair)) {
- if ((RegPair.Source->getReg() == SourceReg) ||
- (RegPair.Destination->getReg() == DestReg))
+ // For AtoS the source must also be different.
+ if (!MoveFromSToA && RegPair.Source->getReg() == SourceReg)
return E;
+ // If paired destination register was modified or used, the source reg
+ // was modified, there is no possibility of finding matching
+ // instruction so exit early.
if (!ModifiedRegUnits.available(DestReg) ||
!UsedRegUnits.available(DestReg) ||
!ModifiedRegUnits.available(SourceReg))
More information about the llvm-commits
mailing list