Skip to content

Incorrect iteration count for loop with unsigned ICMP condition #2375

Closed
@llvmbot

Description

@llvmbot
Bugzilla Link 2003
Resolution FIXED
Resolved on Feb 20, 2008 03:13
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @nlewycky

Extended Description

For the following LLVM code:

define void @​foo(i32 %n) {
entry:
br label %header
header:
%i = phi i32 [ 100, %entry ], [ %i.inc, %next ]
%cond = icmp ult i32 %i, %n
br i1 %cond, label %next, label %return
next:
%i.inc = add i32 %i, 1
br label %header
return:
ret void
}

which contains loop of this form:

unsigned n = ...;
for (unsigned i = 100; i < n; ++i)
;

scalar evolution determines loop iteration count as: (-100 + %n).
This isn't correct, because for %n < 100 we'll get negative number of iterations.

One way to fix it is to add a 'umax' SCEV similar to the 'smax' one. Using it, the answer for the example would be: (100 umax %n) - 100.

Any other ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions