This is beneficial when the shuffle is only used once and end up being generated in a few places when some node is combined into a shuffle.
Details
Diff Detail
- Repository
- rL LLVM
- Build Status
Buildable 37249 Build 37248: arc lint + arc unit
Event Timeline
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16432–16433 | Do you check that both vector_shuffle and extract_vector_elt have the same first argument? | |
| 16434–16436 | Here we have two instructions, and only require that the first one is single-use. Another observation - you end up keeping (using) the instruction you just checked for extra uses. | |
| 16448–16450 | So NewMask is simply inited as a copy of SVN->getMask()? | |
| 16452 | You either need to check that the cast succeeded, or drop dyn_ prefix | |
| 16453 | This could use a comment | |
| test/CodeGen/X86/madd.ll | ||
| 1901–1903 | If i'm reading this correctly this does showcase the need to handle this in backend - it can be introduced there? | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16432–16433 | This is checked bellow. It is because we can match either the first or the second argument, as vector_shuffle does in fact shuffle two vectors together. | |
| 16434–16436 | Even if InsertVal is reused, this transform reduces data dependencies, but indeed do not save anything on the instruction count from. Removing data dependencies is beneficial on its own. | |
| 16448–16450 | I asked mys elf the same question. This doesn't seem to work. | |
| 16452 | The cast must succeed, as we check for it in the if guarding this code, so I'll remove dyn_ | |
| 16453 | I'll add a few comments. | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16448–16450 | Yeah SmallVector doesn't take an ArrayRef, but you can do SmallVector<int, 16> NewMask(Mask.begin(), Mask.end()); | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16434–16436 | So, do we need that one-use restriction here then? | |
| 16448–16450 | SmallVector<int, 16> NewMask(SVN->getMask().begin(), SVN->getMask().end()); then. | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16448–16450 | Please mark comments as resolved as appropriate. | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16456 | There are a few places where isShuffleMaskLegal is used. Some try to flip operands inc ase it isn't legal. Should that be an idiom? | |
Why should this auto close?
It wasn't landed yet. I was wondering if the creation of vector shuffles should be normalized. I think it may be worth doing.
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16456 | I've no objection to you creating a static helper that tries isShuffleMaskLegal with original and commuted masks, and call DAG.getVectorShuffle on success. | |
This looks good to me but i find naming choice really confusing here.
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16429–16467 | Hm, please rename this to ExtractVal instead. | |
| 16432 | Comment is wrong i think, should be | |
| 16456 | ExtrIndex | |
Actually, i have one concern.
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16430 | OldShuffle | |
| 16440–16441 | Just x/y like in comments? | |
| 16446 | Maybe XOffset? | |
| 16450 | Actually, this is not correct. https://llvm.org/docs/LangRef.html#shufflevector-instruction | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16430 | There's no need to rename - tbh we don't know its a shuffle at this stage! | |
| 16450 | That is only true for IR - in the DAG, the result must have the same type as the shuffle operands - so the number of mask elts must match the number of result/operand elts - see SelectionDAG::getVectorShuffle | |
| 16456 | Please can you assert that IndexX's value (and InsIndex come to that) are both in bounds (0 <= idx < Mask.size())? | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16430 | That is true, and this is why the names are what they are. But I have to agree with @lebedev.ri here, the name are very confusing. I'll try to see if I can come up with better names. | |
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16450 | Oh, forgot about that, sorry. An assert later on will be fine then. | |
I still find naming choices to be actively misleading.
LG otherwise.
| lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
|---|---|---|
| 16430 |
But we will only proceed *if* it will be a shuffle. This is a common pattern everywhere else in the code. | |
OldShuffle