Extend trip count instead of truncating IV in LFTR, when legal
authorEhsan Amiri <amehsan@ca.ibm.com>
Thu, 11 Aug 2016 21:31:40 +0000 (21:31 +0000)
committerEhsan Amiri <amehsan@ca.ibm.com>
Thu, 11 Aug 2016 21:31:40 +0000 (21:31 +0000)
commitdbcfea98115be723320f405b6e021a555e709b9b
tree4d09646a35339df572e5565367051bbce8fdbf32
parentf4a30a5d89273ad47939dceef12cf6dd778ecc62
Extend trip count instead of truncating IV in LFTR, when legal

When legal, extending trip count in the loop control logic generates better code compared to truncating IV. This is because

(1) extending trip count is a loop invariant operation (see genLoopLimit where we prove trip count is loop invariant).
(2) Scalar Evolution seems to have problems understanding trunc when computing loop trip count. So removing them allows better analysis performed in Scalar Evolution. (In particular this fixes PR 28363 which is the motivation for this change).

I am not going to perform any performance test. Any degradation caused by this should be an indication of a bug elsewhere.

To prove legality, we rely on SCEV to prove zext(trunc(IV)) == IV (or similarly for sext). If this holds, we can prove equivalence of trunc(IV)==ExitCnt (1) and IV == zext(ExitCnt). Simply take zext of boths sides of (1) and apply the proven equivalence.

This commit contains changes in a newly added testcase which was not included in the previous commit (which was reverted later on).

https://reviews.llvm.org/D23075

llvm-svn: 278421
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/test/Transforms/IndVarSimplify/elim-extend.ll
llvm/test/Transforms/IndVarSimplify/iv-widen-elim-ext.ll
llvm/test/Transforms/IndVarSimplify/lftr-wide-trip-count.ll [new file with mode: 0644]
llvm/test/Transforms/IndVarSimplify/ult-sub-to-eq.ll