From dc7bdc1e7121693df112f2fdb11cc6b88580ba4b Mon Sep 17 00:00:00 2001 From: Sander de Smalen Date: Thu, 15 Jul 2021 12:22:24 +0100 Subject: [PATCH] [LV] Fix determinism for failing scalable-call.ll test. The sort function for emitting an OptRemark was not deterministic, which caused scalable-call.ll to fail on some buildbots. This patch fixes that. This patch also fixes an issue where `Instruction::comesBefore()` is called when two Instructions are in different basic blocks, which would otherwise cause an assertion failure. --- .../Transforms/Vectorize/LoopVectorize.cpp | 9 ++++- .../LoopVectorize/AArch64/scalable-call.ll | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index e70c7f1e7195..e263a5d2038a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6111,10 +6111,15 @@ VectorizationFactor LoopVectorizationCostModel::selectVectorizationFactor( // Emit a report of VFs with invalid costs in the loop. if (!InvalidCosts.empty()) { - // Sort/group per instruction + // Sort/group per instruction (lexicographically within basic blocks). llvm::sort(InvalidCosts, [](InstructionVFPair &A, InstructionVFPair &B) { + const Instruction *AI = A.first, *BI = B.first; + if (AI->getParent() != BI->getParent()) + return AI->getParent() < BI->getParent(); ElementCountComparator ECC; - return A.first->comesBefore(B.first) || ECC(A.second, B.second); + if (AI != BI) + return AI->comesBefore(BI); + return ECC(A.second, B.second); }); // For a list of ordered instruction-vf pairs: diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll index e118e98d44af..28270e89193a 100644 --- a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll @@ -123,6 +123,42 @@ for.cond.cleanup: ; preds = %for.body ret void } +; CHECK-REMARKS: UserVF ignored because of invalid costs. +; CHECK-REMARKS-NEXT: t.c:3:10: Instruction with invalid costs prevented vectorization at VF=(vscale x 1): load +; CHECK-REMARKS-NEXT: t.c:3:40: Instruction with invalid costs prevented vectorization at VF=(vscale x 1): store +; CHECK-REMARKS-NEXT: t.c:3:20: Instruction with invalid costs prevented vectorization at VF=(vscale x 1, vscale x 2): call to llvm.sin.f32 +; CHECK-REMARKS-NEXT: t.c:3:30: Instruction with invalid costs prevented vectorization at VF=(vscale x 1, vscale x 2): call to llvm.sin.f32 +define void @vec_sin_no_mapping_ite(float* noalias nocapture %dst, float* noalias nocapture readonly %src, i64 %n) { +; CHECK: @vec_sin_no_mapping_ite +; CHECK-NOT: