Broadcast code generation emitted instructions in pre-header, while the instruction they are dependent on in the vector loop body.
This resulted in an IL verification error ---- value used before defined.
Details
Diff Detail
Event Timeline
lib/Transforms/Vectorize/LoopVectorize.cpp | ||
---|---|---|
1743 | IIUC we want to check here if Instr is part of the vector loop, right? Wouldn't it be more straight forward to check if the vector loop header dominates Instr? | |
test/Transforms/LoopVectorize/pr37248.ll | ||
1 | Not sure if the property change above means that test/Transforms/LoopVectorize/pr37248.ll is marked as executable. If that's the case, it would be great if you could remove the property before committing. Also, is it worth adding a simple check making sure the loop is vectorized? |
Renato/Florian, thanks for the review.
Ideally, we shouldn't be thinking about where to generate bcast code while we are generating vectorized code. We should have determined such a thing before generating a single line of vector code. In a long run, such a decision would be stored somewhere inside the "vectorization plan" and the code gen should just refer to that.
lib/Transforms/Vectorize/LoopVectorize.cpp | ||
---|---|---|
1743 | Talking about straightforwardness, I suppose the most straightforward way to say it's okay to generate bcast in preheader would be "the value comes from outside of the loop". Instead of computing "Invariant" in a convoluted way, we could do bool SafeToHoist = OrigLoop->isLoopInvariant(V) && (!Instr || DT->dominates(Instr->getParent(), LoopVectorPreHeader)); A lot cleaner this way? There is one caveat. DT is still not fully up-to-date within the vectorizer's code gen At this moment, it's best not to rely on DT w.r.t. instructions inside loop body. If not found (incorrectly), DT will return false and that'll end up in bcast code in preheader, causing a stability issue. So, using "Instruction dominates PH" is more defensive coding. | |
test/Transforms/LoopVectorize/pr37248.ll | ||
1 | Thanks. My bad. copy-paste error. This isn't runnable. OK. Will check for a vector instruction. |
lib/Transforms/Vectorize/LoopVectorize.cpp | ||
---|---|---|
1743 | Right thanks Hideki! IMO the "SafeToHoist" variant is cleaner. |
SafeToHoist logic made straightforward. FileCheck added to lit test. The test passes after the fix.
IIUC we want to check here if Instr is part of the vector loop, right? Wouldn't it be more straight forward to check if the vector loop header dominates Instr?