[PATCH] D22377: [SCEV] trip count calculation for loops with unknown stride
Pankaj Chawla via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 16 16:03:32 PDT 2016
pankajchawla added a comment.
F2275185: indvars.ll <https://reviews.llvm.org/F2275185>
Hi Sanjoy,
This seems to be an issue with indvars pass.
I have uploaded a smaller version of the reproducer (extracted from the original). The bug can be reproduced using this command-
$ opt -indvars indvars.ll -S
Before indvars, the loop for.body's IV is like this-
for.body: ; preds = %for.body.lr.ph, %for.body
%index_Q16.0928 = phi i32 [ 0, %for.body.lr.ph ], [ %add187, %for.body ]
...
%add187 = add nsw i32 %index_Q16.0928, %index_increment_Q16
%cmp = icmp slt i32 %add187, %max_index_Q16
br i1 %cmp, label %for.body, label %sw.epilog.loopexit
The SCEV form of post-incremented IV %add187 is this:
{%index_increment_Q16,+,%index_increment_Q16}<nsw><%for.body>
The backedge taken count of the loop is like this:
((-1 + %max_index_Q16) /u %index_increment_Q16)
After indvars, the IV is extended to 64 bits but the problem is that the stride is zero-extended instead of getting sign-extended. This is incorrect as the stride can be negative. Here's the IR after modification-
for.body.lr.ph: ; preds = %for.cond.preheader
%0 = zext i32 %index_increment_Q16 to i64
br label %for.body
for.body:
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.lr.ph ]
...
%indvars.iv.next = add nuw nsw i64 %indvars.iv, %0
br i1 %cmp, label %for.body, label %sw.epilog.loopexit
I am not familiar with indvars code. Can you please help?
Thanks,
Pankaj
Repository:
rL LLVM
https://reviews.llvm.org/D22377
More information about the llvm-commits
mailing list