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
Event Timeline
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
16432–16433 ↗ | (On Diff #217050) | Do you check that both vector_shuffle and extract_vector_elt have the same first argument? |
16434–16436 ↗ | (On Diff #217050) | 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 ↗ | (On Diff #217050) | So NewMask is simply inited as a copy of SVN->getMask()? |
16452 ↗ | (On Diff #217050) | You either need to check that the cast succeeded, or drop dyn_ prefix |
16453 ↗ | (On Diff #217050) | This could use a comment |
test/CodeGen/X86/madd.ll | ||
1901–1903 ↗ | (On Diff #217050) | 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 ↗ | (On Diff #217050) | 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 ↗ | (On Diff #217050) | 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 ↗ | (On Diff #217050) | I asked mys elf the same question. This doesn't seem to work. |
16452 ↗ | (On Diff #217050) | The cast must succeed, as we check for it in the if guarding this code, so I'll remove dyn_ |
16453 ↗ | (On Diff #217050) | I'll add a few comments. |
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
16448–16450 ↗ | (On Diff #217050) | 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 ↗ | (On Diff #217050) | So, do we need that one-use restriction here then? |
16448–16450 ↗ | (On Diff #217050) | SmallVector<int, 16> NewMask(SVN->getMask().begin(), SVN->getMask().end()); then. |
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
16448–16450 ↗ | (On Diff #217050) | Please mark comments as resolved as appropriate. |
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
16456 ↗ | (On Diff #217064) | 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 ↗ | (On Diff #217064) | I've no objection to you creating a static helper that tries isShuffleMaskLegal with original and commuted masks, and call DAG.getVectorShuffle on success. |
Actually, i have one concern.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
16421 ↗ | (On Diff #217409) | OldShuffle |
16431–16432 ↗ | (On Diff #217409) | Just x/y like in comments? |
16437 ↗ | (On Diff #217409) | Maybe XOffset? |
16441 ↗ | (On Diff #217409) | Actually, this is not correct. https://llvm.org/docs/LangRef.html#shufflevector-instruction |
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
16421 ↗ | (On Diff #217409) | There's no need to rename - tbh we don't know its a shuffle at this stage! |
16441 ↗ | (On Diff #217409) | 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 |
16447 ↗ | (On Diff #217409) | 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 | ||
---|---|---|
16421 ↗ | (On Diff #217409) | 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 | ||
---|---|---|
16441 ↗ | (On Diff #217409) | 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 | ||
---|---|---|
16435 ↗ | (On Diff #217666) |
But we will only proceed *if* it will be a shuffle. This is a common pattern everywhere else in the code. |