[llvm] [AArch64][GlobalISel] Avoid generating inserts for undefs when selecting G_BUILD_VECTOR (PR #84452)

Dhruv Chawla via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 21:05:39 PDT 2024


================
@@ -5934,13 +5934,16 @@ bool AArch64InstructionSelector::selectBuildVector(MachineInstr &I,
 
   // Keep track of the last MI we inserted. Later on, we might be able to save
   // a copy using it.
-  MachineInstr *PrevMI = nullptr;
+  MachineInstr *PrevMI = ScalarToVec;
   for (unsigned i = 2, e = DstSize / EltSize + 1; i < e; ++i) {
     // Note that if we don't do a subregister copy, we can end up making an
     // extra register.
-    PrevMI = &*emitLaneInsert(std::nullopt, DstVec, I.getOperand(i).getReg(),
-                              i - 1, RB, MIB);
-    DstVec = PrevMI->getOperand(0).getReg();
+    Register OpReg = I.getOperand(i).getReg();
+    // Do not emit inserts for undefs
+    if (!getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, OpReg, MRI)) {
----------------
dc03-work wrote:

Okay, I have updated the patch to use this call.

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


More information about the llvm-commits mailing list