llvm.org GIT mirror llvm / 5c80457
SpeculativeExecution: Stop using whitelist for costs Just let TTI's cost do this instead of arbitrarily restricting this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301950 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 2 years ago
3 changed file(s) with 106 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
207207 return false;
208208 }
209209
210 static unsigned ComputeSpeculationCost(const Instruction *I,
211 const TargetTransformInfo &TTI) {
212 switch (Operator::getOpcode(I)) {
213 case Instruction::GetElementPtr:
214 case Instruction::Add:
215 case Instruction::Mul:
216 case Instruction::And:
217 case Instruction::Or:
218 case Instruction::Select:
219 case Instruction::Shl:
220 case Instruction::Sub:
221 case Instruction::LShr:
222 case Instruction::AShr:
223 case Instruction::Xor:
224 case Instruction::ZExt:
225 case Instruction::SExt:
226 case Instruction::Call:
227 case Instruction::BitCast:
228 case Instruction::PtrToInt:
229 case Instruction::IntToPtr:
230 case Instruction::AddrSpaceCast:
231 case Instruction::FPToUI:
232 case Instruction::FPToSI:
233 case Instruction::UIToFP:
234 case Instruction::SIToFP:
235 case Instruction::FPExt:
236 case Instruction::FPTrunc:
237 case Instruction::FAdd:
238 case Instruction::FSub:
239 case Instruction::FMul:
240 case Instruction::FDiv:
241 case Instruction::FRem:
242 case Instruction::ICmp:
243 case Instruction::FCmp:
244 return TTI.getUserCost(I);
245
246 default:
247 return UINT_MAX; // Disallow anything not whitelisted.
248 }
249 }
250
251210 bool SpeculativeExecutionPass::considerHoistingFromTo(
252211 BasicBlock &FromBlock, BasicBlock &ToBlock) {
253212 SmallSet NotHoisted;
263222
264223 unsigned TotalSpeculationCost = 0;
265224 for (auto& I : FromBlock) {
266 const unsigned Cost = ComputeSpeculationCost(&I, *TTI);
225 const unsigned Cost = TTI->getUserCost(&I);
267226 if (Cost != UINT_MAX && isSafeToSpeculativelyExecute(&I) &&
268227 AllPrecedingUsesFromBlockHoisted(&I)) {
269228 TotalSpeculationCost += Cost;
0 ; RUN: opt < %s -S -speculative-execution \
1 ; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
2 ; RUN: | FileCheck %s
3
4 ; CHECK-LABEL: @ifThen_extractvalue(
5 ; CHECK: extractvalue
6 ; CHECK: br i1 true
7 define void @ifThen_extractvalue() {
8 br i1 true, label %a, label %b
9
10 a:
11 %x = extractvalue { i32, i32 } undef, 0
12 br label %b
13
14 b:
15 ret void
16 }
17
18 ; CHECK-LABEL: @ifThen_insertvalue(
19 ; CHECK: insertvalue
20 ; CHECK: br i1 true
21 define void @ifThen_insertvalue() {
22 br i1 true, label %a, label %b
23
24 a:
25 %x = insertvalue { i32, i32 } undef, i32 undef, 0
26 br label %b
27
28 b:
29 ret void
30 }
31
0 ; RUN: opt < %s -S -speculative-execution \
1 ; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
2 ; RUN: | FileCheck %s
3
4 ; CHECK-LABEL: @ifThen_extractelement_constindex(
5 ; CHECK: extractelement
6 ; CHECK: br i1 true
7 define void @ifThen_extractelement_constindex() {
8 br i1 true, label %a, label %b
9
10 a:
11 %x = extractelement <4 x i32> undef, i32 0
12 br label %b
13
14 b:
15 ret void
16 }
17
18 ; CHECK-LABEL: @ifThen_extractelement_varindex(
19 ; CHECK: extractelement
20 ; CHECK: br i1 true
21 define void @ifThen_extractelement_varindex(i32 %idx) {
22 br i1 true, label %a, label %b
23
24 a:
25 %x = extractelement <4 x i32> undef, i32 %idx
26 br label %b
27
28 b:
29 ret void
30 }
31
32 ; CHECK-LABEL: @ifThen_insertelement_constindex(
33 ; CHECK: insertelement
34 ; CHECK: br i1 true
35 define void @ifThen_insertelement_constindex() {
36 br i1 true, label %a, label %b
37
38 a:
39 %x = insertelement <4 x i32> undef, i32 undef, i32 0
40 br label %b
41
42 b:
43 ret void
44 }
45
46 ; CHECK-LABEL: @ifThen_insertelement_varindex(
47 ; CHECK: insertelement
48 ; CHECK: br i1 true
49 define void @ifThen_insertelement_varindex(i32 %idx) {
50 br i1 true, label %a, label %b
51
52 a:
53 %x = insertelement <4 x i32> undef, i32 undef, i32 %idx
54 br label %b
55
56 b:
57 ret void
58 }
59
60 ; CHECK-LABEL: @ifThen_shufflevector(
61 ; CHECK: shufflevector
62 ; CHECK: br i1 true
63 define void @ifThen_shufflevector() {
64 br i1 true, label %a, label %b
65
66 a:
67 %x = shufflevector <4 x i32> undef, <4 x i32> undef, <4 x i32> undef
68 br label %b
69
70 b:
71 ret void
72 }