[LoopVectorization] Invalid code after interleaving add reduction
| Bugzilla Link | 48546 |
| Resolution | INVALID |
| Resolved on | Jan 26, 2021 06:25 |
| Version | trunk |
| OS | Linux |
| CC | @DMG862 |
Extended Description
The following C code generate an issue as follows:
int printf(const char *, ...); int a, b, e; char c, d; int main() { d = 19; for (; d < 45; d++) { char *f = &c; *f &= 1; e = b== 0 ?:a%b; (*f)--; } printf("%d\n", c); }
This code compiled with the following flag causes a bug:
clang test.c -O2 && ./a.out Output: 254
The correct output is '0'.
Upon further investigation, the bug is caused by the interleaving of the Loop Vectorizer.
The follwing command produces correct code:
clang test.c -O2 -mllvm -force-vector-interleave=1 && ./a.out
The root cause is not clear yet, but it seems like there is an add reduction that the loop vectorization legalily determines that it is safe to vectorize, but in this case it generates an incorrect result.
The IVDescriptor.cpp:629, the function call to AddReductionVar for Add reduction finds this to be a signed i1 add reduction, which to me seems like an invalid type.
The test file reduction-small-size.ll is important for this because it has the same type if reduction, but the interleaving is forced to 1, if we force it to 2 we have an invalid code.
Thanks very much for your reply! And apologies for not being able to get back to you sooner.
After further investigation we found that we had internal changes that caused the issue, hence the bug is not relevant to upstream trunk code and we decided to abandon our patch.
Thanks again!
Hello
Trying the C code, I don't seem to see an error with the latest clang. It prints 0 for all the tests I tried. Do you have any more specific instructions for reproducing the issue?
Thanks
Suggested fix:
https://reviews.llvm.org/D93477
My apologies, the above one is a wrong link. This is our suggested fix: https://reviews.llvm.org/D93478
Suggested fix:
https://reviews.llvm.org/D93477