[llvm] dc7bdc1 - [LV] Fix determinism for failing scalable-call.ll test.
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 05:18:29 PDT 2021
Author: Sander de Smalen
Date: 2021-07-15T13:16:59+01:00
New Revision: dc7bdc1e7121693df112f2fdb11cc6b88580ba4b
URL: https://github.com/llvm/llvm-project/commit/dc7bdc1e7121693df112f2fdb11cc6b88580ba4b
DIFF: https://github.com/llvm/llvm-project/commit/dc7bdc1e7121693df112f2fdb11cc6b88580ba4b.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll
Removed:
################################################################################
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: <vscale x
+; CHECK: ret
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %if.end
+ %i.07 = phi i64 [ %inc, %if.end ], [ 0, %entry ]
+ %arrayidx = getelementptr inbounds float, float* %src, i64 %i.07
+ %0 = load float, float* %arrayidx, align 4, !dbg !11
+ %cmp = fcmp ugt float %0, 0.0000
+ br i1 %cmp, label %if.then, label %if.else
+if.then:
+ %1 = tail call fast float @llvm.sin.f32(float %0), !dbg !12
+ br label %if.end
+if.else:
+ %2 = tail call fast float @llvm.sin.f32(float 0.0), !dbg !13
+ br label %if.end
+if.end:
+ %3 = phi float [%1, %if.then], [%2, %if.else]
+ %arrayidx1 = getelementptr inbounds float, float* %dst, i64 %i.07
+ store float %3, float* %arrayidx1, align 4, !dbg !14
+ %inc = add nuw nsw i64 %i.07, 1
+ %exitcond.not = icmp eq i64 %inc, %n
+ br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !llvm.loop !1
+
+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:20: Instruction with invalid costs prevented vectorization at VF=(vscale x 1, vscale x 2): call to llvm.sin.f32
@@ -208,3 +244,4 @@ attributes #3 = { "vector-function-abi-variant"="_ZGV_LLVM_N2v_llvm.sin.f64(sin_
!11 = !DILocation(line: 3, column: 10, scope: !9)
!12 = !DILocation(line: 3, column: 20, scope: !9)
!13 = !DILocation(line: 3, column: 30, scope: !9)
+!14 = !DILocation(line: 3, column: 40, scope: !9)
More information about the llvm-commits
mailing list