Skip to content

Commit 55f3c72

Browse files
committed
Further review comments
Change-Id: I0c20291a8a1d2cbc895890d02aea963323ee48cb
1 parent 6a38c9a commit 55f3c72

File tree

3 files changed

+114
-12
lines changed

3 files changed

+114
-12
lines changed

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,17 +1479,16 @@ InstructionCost ARMTTIImpl::getArithmeticInstrCost(
14791479
if (Ty->isVectorTy())
14801480
return false;
14811481

1482-
auto IsSExtInst = [](const Value *V) -> bool { return isa<SExtInst>(V); };
1483-
auto IsZExtInst = [](const Value *V) -> bool { return isa<ZExtInst>(V); };
1484-
auto IsExtInst = [&, IsSExtInst, IsZExtInst](const Value *V) -> bool {
1485-
return IsSExtInst(V) || IsZExtInst(V);
1482+
auto ValueOpcodesEqual = [](const Value *LHS, const Value *RHS) -> bool {
1483+
return cast<Instruction>(LHS)->getOpcode() ==
1484+
cast<Instruction>(RHS)->getOpcode();
14861485
};
1487-
auto IsExtensionFromHalf = [&, IsSExtInst,
1488-
IsZExtInst](const Value *V) -> bool {
1489-
if (IsSExtInst(V))
1490-
return dyn_cast<SExtInst>(V)->getOperand(0)->getType()->isIntegerTy(16);
1491-
if (IsZExtInst(V))
1492-
return dyn_cast<ZExtInst>(V)->getOperand(0)->getType()->isIntegerTy(16);
1486+
auto IsExtInst = [](const Value *V) -> bool {
1487+
return isa<ZExtInst>(V) || isa<SExtInst>(V);
1488+
};
1489+
auto IsExtensionFromHalf = [&, IsExtInst](const Value *V) -> bool {
1490+
if (IsExtInst(V))
1491+
return cast<Instruction>(V)->getOperand(0)->getType()->isIntegerTy(16);
14931492
return false;
14941493
};
14951494

@@ -1499,15 +1498,15 @@ InstructionCost ARMTTIImpl::getArithmeticInstrCost(
14991498
return false;
15001499
Value *Op0 = BinOp->getOperand(0);
15011500
Value *Op1 = BinOp->getOperand(1);
1502-
if (IsExtInst(Op0) && IsExtInst(Op1)) {
1501+
if (IsExtInst(Op0) && IsExtInst(Op1) && ValueOpcodesEqual(Op0, Op1)) {
15031502
// We're interested in an ext of an i16
15041503
if (!I->getType()->isIntegerTy(32) || !IsExtensionFromHalf(Op0) ||
15051504
!IsExtensionFromHalf(Op1))
15061505
return false;
15071506
// We need to check if this result will be further extended to i64
15081507
// and that all these uses are SExt
15091508
for (auto *U : I->users())
1510-
if (!IsExtInst(dyn_cast<Value>(U)))
1509+
if (!IsExtInst(U))
15111510
return false;
15121511
return true;
15131512
}

llvm/test/Analysis/CostModel/ARM/muls-in-smlal-patterns.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
22
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple thumbv8.1-m.main -mattr=+dsp < %s | FileCheck %s
33
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple thumbv8.1-m.main < %s | FileCheck %s --check-prefix=CHECK-NO-DSP
4+
45
define i64 @test(i16 %a, i16 %b) {
56
; CHECK-LABEL: 'test'
67
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = sext i16 %a to i32
@@ -78,3 +79,25 @@ define i64 @withloads(ptr %pa, ptr %pb, i64 %c) {
7879
%r = add i64 %c, %ms
7980
ret i64 %r
8081
}
82+
83+
define i64 @different_extend_ops(i16 %a, i16 %b) {
84+
; CHECK-LABEL: 'different_extend_ops'
85+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = sext i16 %a to i32
86+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bs = zext i16 %b to i32
87+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %m = mul i32 %as, %bs
88+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = sext i32 %m to i64
89+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %ms
90+
;
91+
; CHECK-NO-DSP-LABEL: 'different_extend_ops'
92+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = sext i16 %a to i32
93+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bs = zext i16 %b to i32
94+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %m = mul i32 %as, %bs
95+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = sext i32 %m to i64
96+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %ms
97+
;
98+
%as = sext i16 %a to i32
99+
%bs = zext i16 %b to i32
100+
%m = mul i32 %as, %bs
101+
%ms = sext i32 %m to i64
102+
ret i64 %ms
103+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple thumbv8.1-m.main -mattr=+dsp < %s | FileCheck %s
3+
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple thumbv8.1-m.main < %s | FileCheck %s --check-prefix=CHECK-NO-DSP
4+
define i64 @test(i16 %a, i16 %b) {
5+
; CHECK-LABEL: 'test'
6+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = zext i16 %a to i32
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bs = zext i16 %b to i32
8+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %m = mul i32 %as, %bs
9+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = zext i32 %m to i64
10+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %ms
11+
;
12+
; CHECK-NO-DSP-LABEL: 'test'
13+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = zext i16 %a to i32
14+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bs = zext i16 %b to i32
15+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %m = mul i32 %as, %bs
16+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = zext i32 %m to i64
17+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %ms
18+
;
19+
%as = zext i16 %a to i32
20+
%bs = zext i16 %b to i32
21+
%m = mul i32 %as, %bs
22+
%ms = zext i32 %m to i64
23+
ret i64 %ms
24+
}
25+
26+
define i64 @withadd(i16 %a, i16 %b, i64 %c) {
27+
; CHECK-LABEL: 'withadd'
28+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = zext i16 %a to i32
29+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bs = zext i16 %b to i32
30+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %m = mul i32 %as, %bs
31+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = zext i32 %m to i64
32+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %r = add i64 %c, %ms
33+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %r
34+
;
35+
; CHECK-NO-DSP-LABEL: 'withadd'
36+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %as = zext i16 %a to i32
37+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %bs = zext i16 %b to i32
38+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %m = mul i32 %as, %bs
39+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = zext i32 %m to i64
40+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %r = add i64 %c, %ms
41+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %r
42+
;
43+
%as = zext i16 %a to i32
44+
%bs = zext i16 %b to i32
45+
%m = mul i32 %as, %bs
46+
%ms = zext i32 %m to i64
47+
%r = add i64 %c, %ms
48+
ret i64 %r
49+
}
50+
51+
define i64 @withloads(ptr %pa, ptr %pb, i64 %c) {
52+
; CHECK-LABEL: 'withloads'
53+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %a = load i16, ptr %pa, align 2
54+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %b = load i16, ptr %pb, align 2
55+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %as = zext i16 %a to i32
56+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %bs = zext i16 %b to i32
57+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %m = mul i32 %as, %bs
58+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = zext i32 %m to i64
59+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %r = add i64 %c, %ms
60+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %r
61+
;
62+
; CHECK-NO-DSP-LABEL: 'withloads'
63+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %a = load i16, ptr %pa, align 2
64+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %b = load i16, ptr %pb, align 2
65+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %as = zext i16 %a to i32
66+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %bs = zext i16 %b to i32
67+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %m = mul i32 %as, %bs
68+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ms = zext i32 %m to i64
69+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %r = add i64 %c, %ms
70+
; CHECK-NO-DSP-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %r
71+
;
72+
%a = load i16, ptr %pa
73+
%b = load i16, ptr %pb
74+
%as = zext i16 %a to i32
75+
%bs = zext i16 %b to i32
76+
%m = mul i32 %as, %bs
77+
%ms = zext i32 %m to i64
78+
%r = add i64 %c, %ms
79+
ret i64 %r
80+
}

0 commit comments

Comments
 (0)