Changes in code style following the mail from James Molloy:
Hi Elena,
Firstly, it looks like your patch *fixes* a bug: the previous code didn't check that the InsertVectorElt it found was actually inserting into lane zero. Could a testcase be added to check this?
[Elena] This function will be used in the upcoming commit ( http://reviews.llvm.org/D11121 ). I'll add more tests there.
Secondly there are some coding style problems here
+llvm::ConstantDataVector *CV = dyn_cast<llvm::ConstantDataVector>(V);
+if (CV)
+return CV->getSplatValue();
(And several other places): This would be more idiomatically written as:
if (auto *CV = dyn_cast<ConstantDataVector>(V))
return CV->getSplatValue();
There are other places where you needlessly use the llvm:: namespace prefix too.
+ // All-zero (our undef) shuffle mask elements.
s/our/or.
for (int i : ShuffleInst->getShuffleMask())
We idiomatically use capitals for our loop induction variables.
if (i != 0 && i != -1)
The function should have a comment stating that it will only detect splats that insert into the zero'th element of the left-hand vector (idiomatic splats). The function could easily be made to detect non-idiomatic splats too, but as long as the function says it explicitly that's good enough, I think.
llvm::InsertElementInst *InsertEltInst =
dyn_cast<llvm::InsertElementInst>(ShuffleInst->getOperand(0));
You don't need to use llvm::, and you can use auto to shorten the line.
Cheers,
James
You don't need llvm:: here.