[PATCH] D22241: [LV] Avoid unnecessary IV scalar-to-vector-to-scalar conversions

Matthew Simpson via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 08:55:02 PDT 2016


mssimpso updated this revision to Diff 63687.
mssimpso marked an inline comment as done.
mssimpso added a comment.

Addressed Adam's comments.

- Renamed ScalarMap to ScalarIVMap since we're currently only using it for induction variables (though it's possible we may want to reuse this in the future to further limit the scalar/vector conversions for other cases).
- Updated ScalarIVMap comment and moved declaration.
- Added comment in vectorizeMemoryInstruction
- Added some pre-instcombine tests.
- Verified compile-time improvement. I see significant speedups in >25 tests from the test-suite with no slowdowns.

Adam,

Thanks for the feedback, and sorry for the lack of explanation. Yes, you understand correctly; here's a quick overview.

When we build the steps for the induction variables we want to be scalar, instead of inserting them into a vector to be maintained in WidenMap, we now leave them as-is and store the steps in ScalarIVMap. Then, whenever we need to scalarize a use of an induction variable, instead of accessing WidenMap and creating an extractelement instruction, we just grab the appropriate value from ScalarIVMap. The relevant extracts are in two places: one in scalarizeInstruction, and one in vectorizeMemoryInstruction.

The approach cuts the number of instructions, pre-instcombine, related to induction variable scalarization by 2/3 since we eliminate, for each step, an insertelement and an extractelement instruction. Compared to always vectorizing the induction variables, scalarizing now doesn't increase the number of instructions. This is because where we previously would have had an extract from the induction variable vector, we now have a scalar step computation. I hope that makes sense!


http://reviews.llvm.org/D22241

Files:
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/LoopVectorize/induction.ll
  test/Transforms/LoopVectorize/reverse_induction.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22241.63687.patch
Type: text/x-patch
Size: 14962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160712/023e8b52/attachment.bin>


More information about the llvm-commits mailing list