[PATCH] D88060: [GISel]: Few InsertVecElt combines
Aditya Nandakumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 15:21:07 PDT 2020
aditya_nandakumar added inline comments.
================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2415
+ auto Index = getConstantVRegVal(MI.getOperand(3).getReg(), MRI);
+ if (!Index || *Index != (NumElts - 1))
+ return false;
----------------
arsenm wrote:
> This could start at any index? Why give up at NumElts - 1?
This is poorly attempting to match the highest index (assuming insert_vec_elts are found with increasing indices) so we can collect as many components as possible.
For eg if we traverse top down (like we currently do)
```
a = insert_vec_elt undef, x, 0
b = insert_vec_elt a, y, 1
```
We'll turn a into
```
a = build_vector x, undef
b = insert_vec_elt a, y, 1
```
Subsequently the insert_vec_elt(build_vec) combine would turn this into
```
b = build_vector x, y
```
Instead starting with b would give the build_vector in one shot.
Maybe the better option to do is check if the current insert_vec_elt is used by insert_vec_elts and bail out.
================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2437
+
+ std::sort(Inserts.begin(), Inserts.end(),
+ [](const std::pair<Register, unsigned> &P1,
----------------
arsenm wrote:
> llvm::sort
Will do.
================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2449
+ Inserts.end());
+ Optional<Register> UndefReg;
+ auto GetUndef = [&]() {
----------------
arsenm wrote:
> Optional doesn't really buy you anything here? You can just use Register()?
Will update.
================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2453
+ return *UndefReg;
+ Builder.setInstr(MI);
+ UndefReg = Builder.buildUndef(DstTy.getScalarType()).getReg(0);
----------------
arsenm wrote:
> I don't think you need to reset the insert point here
I'm not resetting. I'm making sure it's set correctly (MI) so I can insert IMPLICIT_DEFs.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88060/new/
https://reviews.llvm.org/D88060
More information about the llvm-commits
mailing list