[llvm-dev] Canonicalize induction variables

Yaoqing Gao via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 24 18:48:56 PDT 2016


I just subscribed this group.  This is my first time to post a question
(not sure if this is a right place for discussion) after I have a brief
look at LLVM OPT (dev trunk).   I would expect loop simplification and
induction variable canonicalization pass (IndVarSimplify pass) should be
able to convert the following loops into a simple canonical form, i.e.,
there is a canonical induction variable which starts at zero and steps by
one,  getCanonicalInductionVariable() returns  the first PHI node in the
loop header block.

int test1 (int x[], int k, int s) {
  int sum = 0;
  for (int i = 0; i < k; i+=s) {
    sum += x[i];
  }
  return sum;
}

int test2(int x[], int k, int s) {
  int sum = 0;
  for (int i = k; i > 0; i--) {
    sum += x[i];
  }
  return sum;
}

Anyone can help explain why the current LLVM cannot canonicalize induction
variables for the above loops (by design or a limitation to be fixed in the
future)?  Thanks.

-- 
Best regards,

Yaoqing Gao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160824/3a31f2e6/attachment.html>


More information about the llvm-dev mailing list