Skip to content

Commit 8317027

Browse files
committed
Use switch
1 parent d643c8c commit 8317027

File tree

5 files changed

+219
-213
lines changed

5 files changed

+219
-213
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,23 +2327,26 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
23272327
return (LT.first * 2);
23282328
}
23292329

2330-
// If we can't lower fmuladd into an FMA estimate the cost as a floating
2331-
// point mul followed by an add.
2332-
if (IID == Intrinsic::fmuladd)
2330+
switch (IID) {
2331+
case Intrinsic::fmuladd: {
2332+
// If we can't lower fmuladd into an FMA estimate the cost as a floating
2333+
// point mul followed by an add.
2334+
23332335
return thisT()->getArithmeticInstrCost(BinaryOperator::FMul, RetTy,
23342336
CostKind) +
23352337
thisT()->getArithmeticInstrCost(BinaryOperator::FAdd, RetTy,
23362338
CostKind);
2337-
if (IID == Intrinsic::experimental_constrained_fmuladd) {
2339+
}
2340+
case Intrinsic::experimental_constrained_fmuladd: {
23382341
IntrinsicCostAttributes FMulAttrs(
23392342
Intrinsic::experimental_constrained_fmul, RetTy, Tys);
23402343
IntrinsicCostAttributes FAddAttrs(
23412344
Intrinsic::experimental_constrained_fadd, RetTy, Tys);
23422345
return thisT()->getIntrinsicInstrCost(FMulAttrs, CostKind) +
23432346
thisT()->getIntrinsicInstrCost(FAddAttrs, CostKind);
23442347
}
2345-
2346-
if (IID == Intrinsic::sadd_sat || IID == Intrinsic::ssub_sat) {
2348+
case Intrinsic::sadd_sat:
2349+
case Intrinsic::ssub_sat: {
23472350
// Assume a default expansion.
23482351
Type *CondTy = RetTy->getWithNewBitWidth(1);
23492352

@@ -2365,8 +2368,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
23652368
CondTy, Pred, CostKind);
23662369
return Cost;
23672370
}
2368-
2369-
if (IID == Intrinsic::uadd_sat || IID == Intrinsic::usub_sat) {
2371+
case Intrinsic::uadd_sat:
2372+
case Intrinsic::usub_sat: {
23702373
Type *CondTy = RetTy->getWithNewBitWidth(1);
23712374

23722375
Type *OpTy = StructType::create({RetTy, CondTy});
@@ -2383,6 +2386,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
23832386
CmpInst::BAD_ICMP_PREDICATE, CostKind);
23842387
return Cost;
23852388
}
2389+
default:
2390+
break;
2391+
}
23862392

23872393
// Else, assume that we need to scalarize this intrinsic. For math builtins
23882394
// this will emit a costly libcall, adding call overhead and spills. Make it

llvm/test/Analysis/CostModel/ARM/active_lane_mask.ll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
define void @get_lane_mask() {
55
; CHECK-LABEL: 'get_lane_mask'
6-
; CHECK-NEXT: Cost Model: Found an estimated cost of 208 for instruction: %mask_v16i1_i64 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 undef, i64 undef)
7-
; CHECK-NEXT: Cost Model: Found an estimated cost of 104 for instruction: %mask_v8i1_i64 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 undef, i64 undef)
8-
; CHECK-NEXT: Cost Model: Found an estimated cost of 52 for instruction: %mask_v4i1_i64 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 undef, i64 undef)
9-
; CHECK-NEXT: Cost Model: Found an estimated cost of 26 for instruction: %mask_v2i1_i64 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i64(i64 undef, i64 undef)
10-
; CHECK-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %mask_v16i1_i32 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i32(i32 undef, i32 undef)
11-
; CHECK-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %mask_v8i1_i32 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32 undef, i32 undef)
12-
; CHECK-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %mask_v4i1_i32 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 undef, i32 undef)
13-
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %mask_v2i1_i32 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i32(i32 undef, i32 undef)
14-
; CHECK-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %mask_v16i1_i16 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i16(i16 undef, i16 undef)
15-
; CHECK-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %mask_v8i1_i16 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i16(i16 undef, i16 undef)
16-
; CHECK-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %mask_v4i1_i16 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i16(i16 undef, i16 undef)
17-
; CHECK-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %mask_v2i1_i16 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i16(i16 undef, i16 undef)
6+
; CHECK-NEXT: Cost Model: Found an estimated cost of 192 for instruction: %mask_v16i1_i64 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 undef, i64 undef)
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 96 for instruction: %mask_v8i1_i64 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i64(i64 undef, i64 undef)
8+
; CHECK-NEXT: Cost Model: Found an estimated cost of 48 for instruction: %mask_v4i1_i64 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 undef, i64 undef)
9+
; CHECK-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %mask_v2i1_i64 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i64(i64 undef, i64 undef)
10+
; CHECK-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %mask_v16i1_i32 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i32(i32 undef, i32 undef)
11+
; CHECK-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %mask_v8i1_i32 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i32(i32 undef, i32 undef)
12+
; CHECK-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %mask_v4i1_i32 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 undef, i32 undef)
13+
; CHECK-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %mask_v2i1_i32 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i32(i32 undef, i32 undef)
14+
; CHECK-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %mask_v16i1_i16 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i16(i16 undef, i16 undef)
15+
; CHECK-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %mask_v8i1_i16 = call <8 x i1> @llvm.get.active.lane.mask.v8i1.i16(i16 undef, i16 undef)
16+
; CHECK-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %mask_v4i1_i16 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i16(i16 undef, i16 undef)
17+
; CHECK-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %mask_v2i1_i16 = call <2 x i1> @llvm.get.active.lane.mask.v2i1.i16(i16 undef, i16 undef)
1818
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
1919
;
2020
%mask_v16i1_i64 = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i64(i64 undef, i64 undef)

0 commit comments

Comments
 (0)