|
27 | 27 | #include "RISCV.h" |
28 | 28 | #include "RISCVSubtarget.h" |
29 | 29 | #include "llvm/ADT/Statistic.h" |
| 30 | +#include "llvm/Analysis/ValueTracking.h" |
30 | 31 | #include "llvm/CodeGen/LiveDebugVariables.h" |
31 | 32 | #include "llvm/CodeGen/LiveIntervals.h" |
32 | 33 | #include "llvm/CodeGen/LiveStacks.h" |
@@ -196,24 +197,11 @@ static bool hasUndefinedPassthru(const MachineInstr &MI) { |
196 | 197 | } |
197 | 198 |
|
198 | 199 | /// Return true if \p MI is a copy that will be lowered to one or more vmvNr.vs. |
199 | | -static bool isVecCopy(const MachineInstr &MI) { |
200 | | - static const TargetRegisterClass *RVVRegClasses[] = { |
201 | | - &RISCV::VRRegClass, &RISCV::VRM2RegClass, &RISCV::VRM4RegClass, |
202 | | - &RISCV::VRM8RegClass, &RISCV::VRN2M1RegClass, &RISCV::VRN2M2RegClass, |
203 | | - &RISCV::VRN2M4RegClass, &RISCV::VRN3M1RegClass, &RISCV::VRN3M2RegClass, |
204 | | - &RISCV::VRN4M1RegClass, &RISCV::VRN4M2RegClass, &RISCV::VRN5M1RegClass, |
205 | | - &RISCV::VRN6M1RegClass, &RISCV::VRN7M1RegClass, &RISCV::VRN8M1RegClass}; |
206 | | - if (!MI.isCopy()) |
207 | | - return false; |
208 | | - |
209 | | - Register DstReg = MI.getOperand(0).getReg(); |
210 | | - Register SrcReg = MI.getOperand(1).getReg(); |
211 | | - for (const auto &RegClass : RVVRegClasses) { |
212 | | - if (RegClass->contains(DstReg, SrcReg)) { |
213 | | - return true; |
214 | | - } |
215 | | - } |
216 | | - return false; |
| 200 | +static bool isVectorCopy(const TargetRegisterInfo *TRI, |
| 201 | + const MachineInstr &MI) { |
| 202 | + return MI.isCopy() && MI.getOperand(0).getReg().isPhysical() && |
| 203 | + RISCVRegisterInfo::isRVVRegClass( |
| 204 | + TRI->getMinimalPhysRegClass(MI.getOperand(0).getReg())); |
217 | 205 | } |
218 | 206 |
|
219 | 207 | /// Which subfields of VL or VTYPE have values we need to preserve? |
@@ -537,7 +525,7 @@ DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST) { |
537 | 525 | // However it does need valid SEW, i.e. vill must be cleared. The entry to a |
538 | 526 | // function, calls and inline assembly may all set it, so make sure we clear |
539 | 527 | // it for whole register copies. |
540 | | - if (isVecCopy(MI)) |
| 528 | + if (isVectorCopy(ST->getRegisterInfo(), MI)) |
541 | 529 | Res.VILL = true; |
542 | 530 |
|
543 | 531 | return Res; |
@@ -1245,7 +1233,7 @@ static VSETVLIInfo adjustIncoming(VSETVLIInfo PrevInfo, VSETVLIInfo NewInfo, |
1245 | 1233 | // legal for MI, but may not be the state requested by MI. |
1246 | 1234 | void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info, |
1247 | 1235 | const MachineInstr &MI) const { |
1248 | | - if (isVecCopy(MI) && |
| 1236 | + if (isVectorCopy(ST->getRegisterInfo(), MI) && |
1249 | 1237 | (Info.isUnknown() || !Info.isValid() || Info.hasSEWLMULRatioOnly())) { |
1250 | 1238 | // Use an arbitrary but valid AVL and VTYPE so vill will be cleared. It may |
1251 | 1239 | // be coalesced into another vsetvli since we won't demand any fields. |
@@ -1345,7 +1333,7 @@ bool RISCVInsertVSETVLI::computeVLVTYPEChanges(const MachineBasicBlock &MBB, |
1345 | 1333 | transferBefore(Info, MI); |
1346 | 1334 |
|
1347 | 1335 | if (isVectorConfigInstr(MI) || RISCVII::hasSEWOp(MI.getDesc().TSFlags) || |
1348 | | - isVecCopy(MI)) |
| 1336 | + isVectorCopy(ST->getRegisterInfo(), MI)) |
1349 | 1337 | HadVectorOp = true; |
1350 | 1338 |
|
1351 | 1339 | transferAfter(Info, MI); |
@@ -1475,7 +1463,7 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) { |
1475 | 1463 | PrefixTransparent = false; |
1476 | 1464 | } |
1477 | 1465 |
|
1478 | | - if (isVecCopy(MI) && |
| 1466 | + if (isVectorCopy(ST->getRegisterInfo(), MI) && |
1479 | 1467 | !PrevInfo.isCompatible(DemandedFields::all(), CurInfo, LIS)) { |
1480 | 1468 | insertVSETVLI(MBB, MI, MI.getDebugLoc(), CurInfo, PrevInfo); |
1481 | 1469 | PrefixTransparent = false; |
|
0 commit comments