[PATCH] D41939: [LV] Fix incorrect detection of type-promoted Phis
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 01:55:08 PST 2018
mkazantsev created this revision.
mkazantsev added reviewers: hfinkel, dorit, anemet, anna, reames.
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.
https://reviews.llvm.org/D41939
Files:
lib/Transforms/Utils/LoopUtils.cpp
test/Transforms/LoopVectorize/and-plus.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41939.129407.patch
Type: text/x-patch
Size: 5636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180111/d8dfabfe/attachment.bin>
More information about the llvm-commits
mailing list