[PATCH] D101722: [SCEV] Don't require ControlsExit for gt/lt NoWrap
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 8 19:03:14 PDT 2021
efriedma added a comment.
If I'm understanding correctly, the issue you're describing is that if %len is ULONG_MAX in the following loop, on trunk LLVM, the backedge-taken count comes out to zero. This is because of the math in ScalarEvolution::computeBECount: we try to compute `ceil(a/b)` by converting it to `floor((a + b - 1) / b)`, which doesn't work. There are different ways we could address this. For example, we could change around the computation: we can compute `ceil(a/b)` by instead expanding it to `floor(a/b) + umin(a % b, 1)`.
I guess in the meantime, we should add the missing loopHasNoAbnormalExits() check.
declare void @maybe_abort()
define void @test1(i64 %len) {
start:
br label %loop
loop:
%iv = phi i64 [ 0, %start ], [ %iv.inc2, %loop ]
%cmp1 = icmp ult i64 %iv, %len
%iv.inc2 = add nuw i64 %iv, 2
call void @maybe_abort()
br i1 %cmp1, label %loop, label %exit
exit:
ret void
}
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101722/new/
https://reviews.llvm.org/D101722
More information about the llvm-commits
mailing list