[LLVMdev] Loop vectorizer preamble

Arnold Schwaighofer aschwaighofer at apple.com
Sat Aug 30 12:11:09 PDT 2014


> On Aug 30, 2014, at 11:44 AM, James Molloy <james at jamesmolloy.co.uk> wrote:
> 
> Hi Arnold,
> 
> Thanks for the reply. Taking your example:
> 
> This would overflow for say n = 255, VF = 2, char ?
> start = 0
> loop:
>   i = phi (start, next)
>   next = + (i, VF)
>   stop = >= (n, next)
>   br stop, exit, loop
> exit
> 
> Why do we have to use i8 for the induction variable type? If the original add is no-unsigned-wrap, then we could safely extend the induction variable to i32/i64 and have an accurate >= comparison.
> 
> We couldn't do this with an i64 type because there'd be nothing to extend it to, but in practice people still write loops with 32-bit variables a lot of the time.

I agree, and I did something similar to this for types < i32 (r195008)  - secretly hoping nobody would actually write loops that run 2^32 times but I got caught - I got this bug report ;) :http://llvm.org/bugs/show_bug.cgi?id=19846
One could do something similar for i32 types on i64 archs.

You can promote from i32 to i64 and specialize the loop skeleton the way you describe if you are on an i64 arch (or from i16 to i32 if you are on an i32 arch). Keep in mind that the induction variable / vector-scalar loop skeleton is already quite complex and any extension to it should simplify/refactor the current logic.




More information about the llvm-dev mailing list