From 394bad88096074da65c8e230f8a4d8e8355c6d47 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 6 Jul 2021 10:49:13 -0700 Subject: [PATCH] [LV] Disable epilogue vectorization for non-latch exits When skimming through old review discussion, I noticed a post commit comment on an earlier patch which had gone unaddressed. Better late (4 months), than never right? I'm not aware of an active problem with the combination of non-latch exits and epilogue vectorization, but the interaction was not considered and I'm not modivated to make epilogue vectorization work with early exits. If there were a bug in the interaction, it would be pretty hard to hit right now (as we canonicalize towards bottom tested loops), but an upcoming change to allow multiple exit loops will greatly increase the chance for error. Thus, let's play it safe for now. --- lib/Transforms/Vectorize/LoopVectorize.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 7e3a8ead04a..6c1800d2141 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6119,6 +6119,12 @@ bool LoopVectorizationCostModel::isCandidateForEpilogueVectorization( })) return false; + // Epilogue vectorization code has not been auditted to ensure it handles + // non-latch exits properly. It may be fine, but it needs auditted and + // tested. + if (L.getExitingBlock() != L.getLoopLatch()) + return false; + return true; }