Loop vectorizer may recognize the following pattern
%iv = phi i32 ... %x = add i32 %iv, %mask
where %mask is 2^N - 1 as Phi node of type iN which was type-promoted
during canonicalizing transforms. In this case we can vectorize the loop using
its original type and fit more elements into one vector.
The logic that is responsible for this is broken. It only demands that a Phi is
masked, but does not check that after all calculations the result is actually
truncated to type iN. As result, it may falsely detect the following code as
being somehow connected to type-promoted Phis:
char foo(char c) { for (int i = 1; i < 193; i++) { c &= (char) 1; c += (char) 3; } return c; }
Vectorizer tries to calculate the result of this loop in vector of i1, what lead
to incorrect calculations (answer is always 0 or 1 instead of 3 or `4).
This patch strengthens the detecor of this situation. If we have shrinked the
type due to masking, we should later check that the result of all calculations
is either dead or is properly truncated to this type.
I don't think you can assert since you can have uses of ExitInstruction in unreachable blocks and unreachable blocks by definition are outside a loop.