SCEV ignores nuw/nsw when computing MaxBackedgeTakenCount
| Bugzilla Link | 50028 |
| Version | trunk |
| OS | Windows NT |
Extended Description
define void @foo(i32 %n) { entry: br label %loop
loop: %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] %i.next = add nuw nsw i32 %i, 1 %innercmp = icmp ult i32 %i, %n br i1 %innercmp, label %loop, label %exit
exit: ret void }
Running opt -passes='print
Printing analysis 'Scalar Evolution Analysis' for function 'foo':
Classifying expressions for: @foo
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
--> {0,+,1}
Loop %loop: Trip multiple is 1
SCEV understands that %i won't exceed 2^31, but says that the backedge can be taken up to 2^32-1 times. Since it's an upper-bound estimate, it's correct, yet suboptimal.
I guess current algorithm is just looking at the comparison and doesn't try to sharpen facts using branching by UB. It looks like a valid improvement to me.
I'm curious, do you know any transform that fails because of this? I believe the late tendency is to not use max taken count and try to reason about symbolic exact instead.