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

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 8 02:20:00 PST 2024


================
@@ -5963,12 +5966,20 @@ bool AArch64InstructionSelector::selectBuildVector(MachineInstr &I,
     MachineOperand &RegOp = I.getOperand(1);
     RegOp.setReg(Reg);
     RBI.constrainGenericRegister(DstReg, *RC, MRI);
-  } else {
+  } else if (PrevMI) {
     // We don't need a subregister copy. Save a copy by re-using the
     // destination register on the final insert.
-    assert(PrevMI && "PrevMI was null?");
     PrevMI->getOperand(0).setReg(I.getOperand(0).getReg());
     constrainSelectedInstRegOperands(*PrevMI, TII, TRI, RBI);
+  } else {
+    // All the operands (other than the first one) to the G_BUILD_VECTOR were
+    // undef, so PrevMI is nullptr. Emit a copy from the vector made from the
+    // first operand to the destination register.
----------------
madhur13490 wrote:

"Emit a copy from the vector made from the
    // first operand to the destination register."

This is a bit difficult to read. Please simplify.

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


More information about the llvm-commits mailing list