This patch starts small, only detecting sequences of the form <a, a+n, a+2n, a+3n, ...> where a and n are ConstantSDNodes.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | ||
---|---|---|
11706 | Maybe I've missed something, but don't you also need to ensure the first value is zero too, i.e. if (!ExpectedValue.isZero() || PossibleStride.isZero()) return None; | |
11709 | Would this be more efficient (and possibly simpler?) if you just did: if (!ExpectedValue.isZero() || PossibleStride.isZero()) return None; for (unsigned i = 2; i < getNumOperands(); i++) { if (!isa<ConstantSDNode>(getOperand(i))) return None APInt Val = getConstantOperandAPInt(i).trunc(EltSize); if (Val != (i * PossibleStride)) return None; } | |
11713 | I don't think there are any tests that exercise the case where we find a valid sequence as a result of truncating values to the element size. I'm imagining something like this: <i64 0x4000000000000000, 0x4000000000000002, 0x4000000000000004, ...> If it's not too much trouble is it possible to write a unit test for this case to make sure we do the right thing? |
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | ||
---|---|---|
11706 | I had thought the "starting at 0" restriction was baked in. Given this is not the case I think it's likely just as easy to support it as disable it so I'll do the former and thus fix one of the missed optimisations I've highlighted with the tests. | |
11713 | The trunc is really a quirk of type legalisation whereby a vector of i8s is legal but i8 scalars are not. The example you're proposing is likely to be optimised away before we get this far. The code itself is unconditional though so there is no untested code path. |
Extended to allow an arbitrary start index.
I'm posting this update for comment but it is my intention to split the patch because the findMoreOptimalIndexType change is not great and better done without needing isConstantSequence.
llvm/include/llvm/CodeGen/SelectionDAGNodes.h | ||
---|---|---|
2084 | I know the comments are out of sync. I'll update them when splitting the patch. |
Rebased and removed findMoreOptimalIndexType change, which will form a separate patch. I've kept the gather/scatter tests because they are the inspiration for the work and show why the follow on patch is of value.
I know the comments are out of sync. I'll update them when splitting the patch.