This is an archive of the discontinued LLVM Phabricator instance.

Code style changes (VectorUtils.cpp)
ClosedPublic

Authored by delena on Aug 30 2015, 4:25 AM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

delena updated this revision to Diff 33532.Aug 30 2015, 4:25 AM
delena retitled this revision from to Code style changes (VectorUtils.cpp).
delena updated this object.
delena added a reviewer: jmolloy.
delena set the repository for this revision to rL LLVM.
delena added subscribers: hfinkel, llvm-commits.
jmolloy accepted this revision.Aug 30 2015, 6:42 AM
jmolloy edited edge metadata.

Apart from my one comment, LGTM.

Thankyou for making these changes, Elena!

../lib/Analysis/VectorUtils.cpp
418 ↗(On Diff #33532)

You don't need llvm:: here.

This revision is now accepted and ready to land.Aug 30 2015, 6:42 AM
This revision was automatically updated to reflect the committed changes.