[PATCH] D49151: [SimplifyIndVar] Avoid generating truncate instructions with non-hoisted Load operand.

Abderrazek Zaafrani via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 10 12:55:55 PDT 2018


az created this revision.
az added reviewers: sanjoy, efriedma.
Herald added a reviewer: javed.absar.
Herald added subscribers: hiraditya, kristof.beyls.

One of the transformation done by the SimplyIndVar is to widen instructions, eliminate sign/zero extend instructions, and reduce the generation of truncate instructions when legal. Let's consider the following common C code fragment within a loop:
p = *(base + x*i);        // i is the loop induction variable

If x is some load instruction that is hoisted outside the loop by LICM, then SimplyIndVar generates optimal code by not emitting any truncate instructions after widening. In case x is not hoisted, then the code generated is sub-optimal and it is mainly because SimplyIndVar relies on scalar evolution that can not handle loop variant expression. This patch handle the non-hoisted case and generates similar code to the hoisted case (see output of .ll file with and without patch).

The performance effect of redundant truncate and extend instructions can be big on strength reduction and on the backend when choosing the appropriate addressing mode.

No performance change on spec for ARM A72 but significant improvement on proprietary benchmark. Note that an alternative to this patch is to move SimplifyIndVar pass after PRE because PRE hoists more loop invariant code than LICM given that it uses a less conservative but expensive version of alias analysis.  We opted not to make any change into pass ordering which can affect performance more than a local change.


Repository:
  rL LLVM

https://reviews.llvm.org/D49151

Files:
  llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
  llvm/test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49151.154858.patch
Type: text/x-patch
Size: 11019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/05b3064a/attachment.bin>


More information about the llvm-commits mailing list