From 4f1b8e266efd878f320ae4758878bab160089ff0 Mon Sep 17 00:00:00 2001 From: Sander de Smalen Date: Mon, 26 Jul 2021 17:12:51 +0100 Subject: [PATCH] [LV] Don't let ForceTargetInstructionCost override Invalid cost. Invalid costs can be used to avoid vectorization with a given VF, which is used for scalable vectors to avoid things that the code-generator cannot handle. If we override the cost using the -force-target-instruction-cost option of the LV, we would override this mechanism, rendering the flag useless. This change ensures the cost is only overriden when the original cost that was calculated is valid. That allows the flag to be used in combination with the -scalable-vectorization option. Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D106677 --- lib/Transforms/Vectorize/LoopVectorize.cpp | 3 ++- test/Transforms/LoopVectorize/AArch64/scalable-call.ll | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 564812bc8a5..6d747f8af47 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6887,7 +6887,8 @@ LoopVectorizationCostModel::expectedCost( VectorizationCostTy C = getInstructionCost(&I, VF); // Check if we should override the cost. - if (ForceTargetInstructionCost.getNumOccurrences() > 0) + if (C.first.isValid() && + ForceTargetInstructionCost.getNumOccurrences() > 0) C.first = InstructionCost(ForceTargetInstructionCost); // Keep a list of instructions with invalid costs. diff --git a/test/Transforms/LoopVectorize/AArch64/scalable-call.ll b/test/Transforms/LoopVectorize/AArch64/scalable-call.ll index d7a3f719e15..71c839051b4 100644 --- a/test/Transforms/LoopVectorize/AArch64/scalable-call.ll +++ b/test/Transforms/LoopVectorize/AArch64/scalable-call.ll @@ -1,6 +1,9 @@ ; RUN: opt -S -loop-vectorize -force-vector-interleave=1 -instcombine -mattr=+sve -mtriple aarch64-unknown-linux-gnu -scalable-vectorization=on \ ; RUN: -pass-remarks-missed=loop-vectorize < %s 2>%t | FileCheck %s ; RUN: cat %t | FileCheck %s --check-prefix=CHECK-REMARKS +; RUN: opt -S -loop-vectorize -force-vector-interleave=1 -force-target-instruction-cost=1 -instcombine -mattr=+sve -mtriple aarch64-unknown-linux-gnu \ +; RUN: -scalable-vectorization=on -pass-remarks-missed=loop-vectorize < %s 2>%t | FileCheck %s +; RUN: cat %t | FileCheck %s --check-prefix=CHECK-REMARKS define void @vec_load(i64 %N, double* nocapture %a, double* nocapture readonly %b) { ; CHECK-LABEL: @vec_load