[llvm] [AArch64] Fix MatchDup Lane Out Of Range In AArch64 (PR #101275)

David Green via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 05:56:43 PDT 2024


================
@@ -288,10 +288,17 @@ bool matchDupFromBuildVector(int Lane, MachineInstr &MI,
                              MachineRegisterInfo &MRI,
                              ShuffleVectorPseudo &MatchInfo) {
   assert(Lane >= 0 && "Expected positive lane?");
+  int NumElements = MRI.getType(MI.getOperand(1).getReg()).getNumElements();
   // Test if the LHS is a BUILD_VECTOR. If it is, then we can just reference the
   // lane's definition directly.
   auto *BuildVecMI = getOpcodeDef(TargetOpcode::G_BUILD_VECTOR,
                                   MI.getOperand(1).getReg(), MRI);
----------------
davemgreen wrote:

Could we do
```
  auto *BuildVecMI = getOpcodeDef(TargetOpcode::G_BUILD_VECTOR,
                                  MI.getOperand(Lane < NumElements ? 1 : 2).getReg(), MRI);
```

It just stops it from having to look into getOpcodeDef twice.

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


More information about the llvm-commits mailing list