[PATCH] D52881: [LV] Do not create SCEVs on broken IR in emitTransformedIndex. PR39160

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 4 04:28:43 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: hsaito, fhahn, sanjoy, jlebar.
Herald added subscribers: arphaman, rkruppe, javed.absar.

At the point when we perform `emitTransformedIndex`, we have a broken IR (in
particular, we have Phis for which not every incoming value is properly set). On
such IR, it is illegal to create SCEV expressions, because their internal
simplification process may try to prove some predicates and break when it
stumbles across some broken IR.

The only purpose of using SCEV in this particular place is attempt to simplify
the generated code slightly. It seems that the result isn't worth it, because
some trivial cases (like addition of zero and multiplication by 1) can be
handled separately if needed, but more generally InstCombine is able to achieve
the goals we want to achieve by using SCEV.

This patch fixes a functional crash described in PR39160, and as side-effect it
also generates a bit smarter code in some simple cases. It also may cause some
optimality loss (i.e. we will now generate `mul` by power of `2` instead of
shift etc), but there is nothing what InstCombine could not handle later. In
case of dire need, we can support more trivial cases just in place.

Note that this patch only fixes one particular case of the general problem that
LV misuses SCEV, attempting to create SCEVs or prove predicates on invalid IR.
The general solution, however, seems complex enough.


https://reviews.llvm.org/D52881

Files:
  lib/Transforms/Vectorize/LoopVectorize.cpp
  test/Transforms/LoopVectorize/X86/constant-fold.ll
  test/Transforms/LoopVectorize/X86/pr39160.ll
  test/Transforms/LoopVectorize/induction.ll
  test/Transforms/LoopVectorize/iv_outside_user.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52881.168267.patch
Type: text/x-patch
Size: 14553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181004/3162ec4c/attachment.bin>


More information about the llvm-commits mailing list