If it is legal and profitable to vectorize integer division operations
and some of the operands are undefs, need to replace these undefs in the
vector operands elements with some actual values. Otherwise, such
division operations will be replaced by the vector poison values in the
instcombiner. It leads to incorrect llvm ir per https://llvm.org/docs/LangRef.html#poisonvalues. According to this document "Vector elements may be independently poisoned. Therefore, transforms on instructions such as shufflevector must be careful to propagate poison across values or elements only as allowed by the original code."
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I am not sure I understand why you are trying to get rid of the undef operands. Could you provide a code example that shows the issue?
+1
llvm/test/Transforms/SLPVectorizer/X86/arith-div-undef.ll | ||
---|---|---|
6 | This is *NOT* a miscompile: https://alive2.llvm.org/ce/z/iMu-eF |
The test test/Transforms/SLPVectorizer/X86/arith-div-undef.ll shows the problem. We have a gather of sdivs results, 2 of them are poisonous. And generally speaking, this gather shall end up with a vector <poison, sdiv1, sdiv2, sdiv3, poison, sdiv4, sdiv5, sdiv6>. But instead, the compiler generates just <8 x i32> poison. I think this result is more poisonous than the original one. Extract from lane 1, for example, should be different for these results.
Here is an example with just instcombiner https://godbolt.org/z/9rxesoM47
llvm/test/Transforms/SLPVectorizer/X86/arith-div-undef.ll | ||
---|---|---|
6 | Yes, also checked it via alive but not sure if alive is correct here. |
llvm/test/Transforms/SLPVectorizer/X86/arith-div-undef.ll | ||
---|---|---|
6 | https://llvm.org/docs/LangRef.html#sdiv-instruction |
llvm/test/Transforms/SLPVectorizer/X86/arith-div-undef.ll | ||
---|---|---|
6 | Yep, thought about this. But thought that a buildvector has different behavior. Probably here the whole program becomes UB after division by undef. |
This is *NOT* a miscompile: https://alive2.llvm.org/ce/z/iMu-eF