[llvm] [GISel][SDAG] Avoid push_back in loops for some shuffle mask handling. (PR #119434)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 11:55:15 PST 2024


================
@@ -6173,8 +6173,7 @@ LegalizerHelper::equalizeVectorShuffleLengths(MachineInstr &MI) {
     // Extend mask to match new destination vector size with
     // undef values.
     SmallVector<int, 16> NewMask(Mask);
-    for (unsigned I = MaskNumElts; I < SrcNumElts; ++I)
-      NewMask.push_back(-1);
+    NewMask.resize(SrcNumElts, -1);
----------------
topperc wrote:

We're already using the constructor to copy the first part of the Mask. We could do

```
SmallVector<int, 16> NewMask(SrcNumElts, -1);
std::copy(NewMask.begin(), Mask.begin(), Mask.end())
```

Then we'd have the correct size at the start.

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


More information about the llvm-commits mailing list