The following example:
define i8 @foo(i8 %v) local_unnamed_addr #0 {
region.0:
%0 = mul nsw i8 16, %v %1 = mul nsw i8 0, %0 %2 = mul nsw i8 1, %1 ret i8 %2
}
Causes nary reassociation to fall into infinite loop.
The root cause is in overflowed SCEV expression (16*v)*(16*v) - which is 0 for "i8" type.
The patch inserts a check to avoid the case.