Skip to content

Commit ca9f165

Browse files
Addressing reviewers.
Comparing against the default cost, and no longer restricting to scalable types.
1 parent d872bc4 commit ca9f165

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/IR/IntrinsicInst.h"
1818
#include "llvm/IR/Module.h"
1919
#include "llvm/IR/Operator.h"
20+
#include "llvm/IR/PatternMatch.h"
2021
#include "llvm/InitializePasses.h"
2122
#include "llvm/Support/CommandLine.h"
2223
#include <optional>

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6950,24 +6950,27 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
69506950
Legal->isInvariant(Op2))
69516951
Op2Info.Kind = TargetTransformInfo::OK_UniformValue;
69526952

6953+
SmallVector<const Value *, 4> Operands(I->operand_values());
6954+
auto InstrCost = TTI.getArithmeticInstrCost(
6955+
I->getOpcode(), VectorTy, CostKind,
6956+
{TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
6957+
Op2Info, Operands, I);
6958+
69536959
// Some targets replace frem with vector library calls.
6954-
if (I->getOpcode() == Instruction::FRem && VectorTy->isScalableTy()) {
6960+
if (I->getOpcode() == Instruction::FRem) {
69556961
LibFunc Func;
69566962
if (TLI->getLibFunc(I->getOpcode(), I->getType(), Func)) {
69576963
if (TLI->isFunctionVectorizable(TLI->getName(Func))) {
69586964
SmallVector<Type *, 4> OpTypes;
69596965
for (auto &Op : I->operands())
69606966
OpTypes.push_back(Op->getType());
6961-
return TTI.getCallInstrCost(nullptr, VectorTy, OpTypes, CostKind);
6967+
auto CallCost =
6968+
TTI.getCallInstrCost(nullptr, VectorTy, OpTypes, CostKind);
6969+
return std::min(InstrCost, CallCost);
69626970
}
69636971
}
69646972
}
6965-
6966-
SmallVector<const Value *, 4> Operands(I->operand_values());
6967-
return TTI.getArithmeticInstrCost(
6968-
I->getOpcode(), VectorTy, CostKind,
6969-
{TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None},
6970-
Op2Info, Operands, I);
6973+
return InstrCost;
69716974
}
69726975
case Instruction::FNeg: {
69736976
return TTI.getArithmeticInstrCost(

llvm/test/Analysis/CostModel/AArch64/arith-fp-sve.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 4
2-
; RUN: opt -mattr=+sve -mattr=+fullfp16 -enable-no-nans-fp-math -disable-output -passes="print<cost-model>" %s 2>&1 | FileCheck %s
3-
4-
target triple = "aarch64-unknown-linux-gnu"
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2+
; RUN: opt < %s -enable-no-nans-fp-math -passes="print<cost-model>" 2>&1 -disable-output -mtriple=aarch64 -mattr=+fullfp16 -mattr=+sve | FileCheck %s
53

4+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
65

76
define void @fadd() {
87
; CHECK-LABEL: 'fadd'

llvm/test/Analysis/CostModel/AArch64/arith-fp.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
22
; RUN: opt < %s -enable-no-nans-fp-math -passes="print<cost-model>" 2>&1 -disable-output -mtriple=aarch64 -mattr=+fullfp16 | FileCheck %s
33

4-
target triple = "aarch64-unknown-linux-gnu"
4+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
55

66
define i32 @fadd(i32 %arg) {
77
; CHECK-LABEL: 'fadd'

0 commit comments

Comments
 (0)