[PATCH] D155049: [ScalarEvolution] Infer loop max trip count from memory accesses

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 11:57:44 PDT 2023


nikic added a comment.

In D155049#4514907 <https://reviews.llvm.org/D155049#4514907>, @Peakulorain wrote:

> Thanks for your help, the above case is indeed filtered out by constraints. But please see :
>
>   define void @test(i32 signext %len) {...
>   for.body:
>     %iv = phi i8 [ %inc, %for.body ], [ 0, %for.body.preheader ]
>     %idxprom = zext i8 %iv to i64
>     %arrayidx = getelementptr inbounds [500 x i32], [500 x i32]* %a, i64 0, i64 %idxprom
>     store i32 0, i32* %arrayidx, align 4
>     %inc = add nuw nsw i8 %iv, 1
>     %inc_zext = zext i8 %inc to i32
>     %cmp = icmp slt i32 %inc_zext, %len
>     br i1 %cmp, label %for.body, label %loopexit
>     ...
>   }
>
> this case would get **{%a,+,4}<nuw><%for.body>**. In such a situation, I think it is necessary to calculate how many iterations to wrap. :)

Doesn't the `add nuw` exclude wrapping in this case though? This is why SCEV concludes it's okay to look through the zext.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155049/new/

https://reviews.llvm.org/D155049



More information about the llvm-commits mailing list