Skip to content

Commit 0f14b2e

Browse files
Revert "[BPI] Improve static heuristics for integer comparisons"
This reverts commit 50c743f. Patch will be split to smaller ones.
1 parent 5a7b61b commit 0f14b2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1932
-4757
lines changed

compiler-rt/test/profile/Linux/counter_promo_for.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ __attribute__((noinline)) void foo(int n, int N) {
2222
// PROMO: load{{.*}}@__profc_foo{{.*}} 3){{.*}}
2323
// PROMO-NEXT: add
2424
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 3){{.*}}
25-
// PROMO: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
26-
// PROMO-NEXT: add
27-
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
28-
// PROMO-NEXT: load{{.*}}@__profc_foo{{.*}} 0){{.*}}
25+
// PROMO: load{{.*}}@__profc_foo{{.*}} 0){{.*}}
2926
// PROMO-NEXT: add
3027
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 0){{.*}}
28+
// PROMO-NEXT: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
29+
// PROMO-NEXT: add
30+
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
3131
// PROMO: load{{.*}}@__profc_foo{{.*}} 2){{.*}}
3232
// PROMO-NEXT: add
3333
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 2){{.*}}
3434
//
3535
// NOPROMO-LABEL: @foo
36-
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
37-
// NOPROMO-NEXT: add
38-
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
3936
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 0){{.*}}
4037
// NOPROMO-NEXT: add
4138
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 0){{.*}}
39+
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
40+
// NOPROMO-NEXT: add
41+
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
4242
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 2){{.*}}
4343
// NOPROMO-NEXT: add
4444
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 2){{.*}}

compiler-rt/test/profile/Linux/counter_promo_while.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ int g;
1717
__attribute__((noinline)) void bar(int i) { g += i; }
1818
__attribute__((noinline)) void foo(int n, int N) {
1919
// PROMO-LABEL: @foo
20-
// PROMO: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
21-
// PROMO-NEXT: add
22-
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
23-
// PROMO-NEXT: load{{.*}}@__profc_foo{{.*}} 0){{.*}}
20+
// PROMO: load{{.*}}@__profc_foo{{.*}} 0){{.*}}
2421
// PROMO-NEXT: add
2522
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 0){{.*}}
23+
// PROMO-NEXT: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
24+
// PROMO-NEXT: add
25+
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
2626
// PROMO-NEXT: load{{.*}}@__profc_foo{{.*}} 2){{.*}}
2727
// PROMO-NEXT: add
2828
// PROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 2){{.*}}
2929
//
3030
// NOPROMO-LABEL: @foo
31-
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
32-
// NOPROMO-NEXT: add
33-
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
3431
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 0){{.*}}
3532
// NOPROMO-NEXT: add
3633
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 0){{.*}}
34+
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 1){{.*}}
35+
// NOPROMO-NEXT: add
36+
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 1){{.*}}
3737
// NOPROMO: load{{.*}}@__profc_foo{{.*}} 2){{.*}}
3838
// NOPROMO-NEXT: add
3939
// NOPROMO-NEXT: store{{.*}}@__profc_foo{{.*}} 2){{.*}}

llvm/include/llvm/Analysis/BranchProbabilityInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class BranchProbabilityInfo {
315315
bool calcColdCallHeuristics(const BasicBlock *BB);
316316
bool calcPointerHeuristics(const BasicBlock *BB);
317317
bool calcLoopBranchHeuristics(const BasicBlock *BB, const LoopInfo &LI);
318-
bool calcIntegerHeuristics(const BasicBlock *BB, const TargetLibraryInfo *TLI);
318+
bool calcZeroHeuristics(const BasicBlock *BB, const TargetLibraryInfo *TLI);
319319
bool calcFloatingPointHeuristics(const BasicBlock *BB);
320320
bool calcInvokeHeuristics(const BasicBlock *BB);
321321
};

llvm/lib/Analysis/BranchProbabilityInfo.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ static const uint32_t CC_NONTAKEN_WEIGHT = 64;
122122
static const uint32_t PH_TAKEN_WEIGHT = 20;
123123
static const uint32_t PH_NONTAKEN_WEIGHT = 12;
124124

125-
static const uint32_t INTH_TAKEN_WEIGHT = 20;
126-
static const uint32_t INTH_NONTAKEN_WEIGHT = 12;
125+
static const uint32_t ZH_TAKEN_WEIGHT = 20;
126+
static const uint32_t ZH_NONTAKEN_WEIGHT = 12;
127127

128128
static const uint32_t FPH_TAKEN_WEIGHT = 20;
129129
static const uint32_t FPH_NONTAKEN_WEIGHT = 12;
@@ -856,7 +856,7 @@ bool BranchProbabilityInfo::calcLoopBranchHeuristics(const BasicBlock *BB,
856856
return true;
857857
}
858858

859-
bool BranchProbabilityInfo::calcIntegerHeuristics(const BasicBlock *BB,
859+
bool BranchProbabilityInfo::calcZeroHeuristics(const BasicBlock *BB,
860860
const TargetLibraryInfo *TLI) {
861861
const BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
862862
if (!BI || !BI->isConditional())
@@ -873,21 +873,10 @@ bool BranchProbabilityInfo::calcIntegerHeuristics(const BasicBlock *BB,
873873
return dyn_cast<ConstantInt>(V);
874874
};
875875

876-
BranchProbability TakenProb(INTH_TAKEN_WEIGHT,
877-
INTH_TAKEN_WEIGHT + INTH_NONTAKEN_WEIGHT);
878-
BranchProbability UntakenProb(INTH_NONTAKEN_WEIGHT,
879-
INTH_TAKEN_WEIGHT + INTH_NONTAKEN_WEIGHT);
880876
Value *RHS = CI->getOperand(1);
881877
ConstantInt *CV = GetConstantInt(RHS);
882-
if (!CV) {
883-
// X == Y -> Unlikely
884-
// Otherwise -> Likely
885-
if (CI->isTrueWhenEqual())
886-
std::swap(TakenProb, UntakenProb);
887-
setEdgeProbability(
888-
BB, SmallVector<BranchProbability, 2>({TakenProb, UntakenProb}));
889-
return true;
890-
}
878+
if (!CV)
879+
return false;
891880

892881
// If the LHS is the result of AND'ing a value with a single bit bitmask,
893882
// we don't have information about probabilities.
@@ -975,6 +964,10 @@ bool BranchProbabilityInfo::calcIntegerHeuristics(const BasicBlock *BB,
975964
return false;
976965
}
977966

967+
BranchProbability TakenProb(ZH_TAKEN_WEIGHT,
968+
ZH_TAKEN_WEIGHT + ZH_NONTAKEN_WEIGHT);
969+
BranchProbability UntakenProb(ZH_NONTAKEN_WEIGHT,
970+
ZH_TAKEN_WEIGHT + ZH_NONTAKEN_WEIGHT);
978971
if (!isProb)
979972
std::swap(TakenProb, UntakenProb);
980973

@@ -1228,7 +1221,7 @@ void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI,
12281221
continue;
12291222
if (calcPointerHeuristics(BB))
12301223
continue;
1231-
if (calcIntegerHeuristics(BB, TLI))
1224+
if (calcZeroHeuristics(BB, TLI))
12321225
continue;
12331226
if (calcFloatingPointHeuristics(BB))
12341227
continue;

llvm/test/Analysis/BranchProbabilityInfo/loop.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ for.body:
263263
%0 = load i32, i32* %c, align 4
264264
%cmp1 = icmp eq i32 %0, %i.011
265265
br i1 %cmp1, label %for.inc5, label %if.end
266-
; CHECK: edge for.body -> for.inc5 probability is 0x30000000 / 0x80000000 = 37.50%
267-
; CHECK: edge for.body -> if.end probability is 0x50000000 / 0x80000000 = 62.50%
266+
; CHECK: edge for.body -> for.inc5 probability is 0x40000000 / 0x80000000 = 50.00%
267+
; CHECK: edge for.body -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
268268

269269
if.end:
270270
call void @g1()
@@ -324,22 +324,22 @@ for.body3:
324324
%0 = load i32, i32* %c, align 4
325325
%cmp4 = icmp eq i32 %0, %j.017
326326
br i1 %cmp4, label %for.inc, label %if.end
327-
; CHECK: edge for.body3 -> for.inc probability is 0x30000000 / 0x80000000 = 37.50%
328-
; CHECK: edge for.body3 -> if.end probability is 0x50000000 / 0x80000000 = 62.50%
327+
; CHECK: edge for.body3 -> for.inc probability is 0x40000000 / 0x80000000 = 50.00%
328+
; CHECK: edge for.body3 -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
329329

330330
if.end:
331331
%1 = load i32, i32* %arrayidx5, align 4
332332
%cmp6 = icmp eq i32 %1, %j.017
333333
br i1 %cmp6, label %for.inc, label %if.end8
334-
; CHECK: edge if.end -> for.inc probability is 0x30000000 / 0x80000000 = 37.50%
335-
; CHECK: edge if.end -> if.end8 probability is 0x50000000 / 0x80000000 = 62.50%
334+
; CHECK: edge if.end -> for.inc probability is 0x40000000 / 0x80000000 = 50.00%
335+
; CHECK: edge if.end -> if.end8 probability is 0x40000000 / 0x80000000 = 50.00%
336336

337337
if.end8:
338338
%2 = load i32, i32* %arrayidx9, align 4
339339
%cmp10 = icmp eq i32 %2, %j.017
340340
br i1 %cmp10, label %for.inc, label %if.end12
341-
; CHECK: edge if.end8 -> for.inc probability is 0x30000000 / 0x80000000 = 37.50%
342-
; CHECK: edge if.end8 -> if.end12 probability is 0x50000000 / 0x80000000 = 62.50%
341+
; CHECK: edge if.end8 -> for.inc probability is 0x40000000 / 0x80000000 = 50.00%
342+
; CHECK: edge if.end8 -> if.end12 probability is 0x40000000 / 0x80000000 = 50.00%
343343

344344
if.end12:
345345
call void @g2()

llvm/test/Analysis/BranchProbabilityInfo/integer_heuristics.ll renamed to llvm/test/Analysis/BranchProbabilityInfo/zero_heuristics.ll

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -101,54 +101,3 @@ for.inc:
101101
exit:
102102
ret void
103103
}
104-
105-
declare void @foo()
106-
107-
; CHECK-LABEL: foo1
108-
define i32 @foo1(i32 %x, i32 %y, i8 signext %z, i8 signext %w) {
109-
entry:
110-
%c = icmp eq i32 %x, %y
111-
br i1 %c, label %then, label %else
112-
; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
113-
; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
114-
then:
115-
tail call void @foo()
116-
br label %else
117-
; CHECK: edge then -> else probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
118-
else:
119-
%v = phi i8 [ %z, %then ], [ %w, %entry ]
120-
%r = sext i8 %v to i32
121-
ret i32 %r
122-
}
123-
124-
; CHECK-LABEL: foo2
125-
define i32 @foo2(i32 %x, i32 %y, i8 signext %z, i8 signext %w) {
126-
entry:
127-
%c = icmp ne i32 %x, %y
128-
br i1 %c, label %then, label %else
129-
; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50%
130-
; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50%
131-
then:
132-
br label %else
133-
; CHECK: edge then -> else probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
134-
else:
135-
%v = phi i8 [ %z, %then ], [ %w, %entry ]
136-
%r = sext i8 %v to i32
137-
ret i32 %r
138-
}
139-
140-
; CHECK-LABEL: foo3
141-
define i32 @foo3(i32 %x, i32 %y, i8 signext %z, i8 signext %w) {
142-
entry:
143-
%c = icmp ult i32 %x, %y
144-
br i1 %c, label %then, label %else
145-
; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50%
146-
; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50%
147-
then:
148-
br label %else
149-
; CHECK: edge then -> else probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
150-
else:
151-
%v = phi i8 [ %z, %then ], [ %w, %entry ]
152-
%r = sext i8 %v to i32
153-
ret i32 %r
154-
}

llvm/test/CodeGen/AArch64/aarch64-gep-opt.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ exit:
8888
; CHECK-LABEL: test_GEP_across_BB:
8989
; CHECK: ldr {{w[0-9]+}}, [{{x[0-9]+}}, #528]
9090
; CHECK: ldr {{w[0-9]+}}, [{{x[0-9]+}}, #532]
91+
; CHECK-NOT: add
9192
; CHECK: str {{w[0-9]+}}, [{{x[0-9]+}}, #532]
9293
; CHECK: str {{w[0-9]+}}, [{{x[0-9]+}}, #528]
9394

llvm/test/CodeGen/AArch64/branch-relax-alignment.ll

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
21
; RUN: llc -mtriple=aarch64-apple-darwin -aarch64-bcc-offset-bits=4 -align-all-nofallthru-blocks=4 < %s | FileCheck %s
32

43
; Long branch is assumed because the block has a higher alignment
54
; requirement than the function.
65

7-
define i32 @invert_bcc_block_align_higher_func(i32 %x, i32 %y) align 4 #0 {
86
; CHECK-LABEL: invert_bcc_block_align_higher_func:
9-
; CHECK: ; %bb.0:
10-
; CHECK-NEXT: cmp w0, w1
11-
; CHECK-NEXT: b.ne LBB0_1
12-
; CHECK-NEXT: b LBB0_2
13-
; CHECK-NEXT: LBB0_1: ; %bb2
14-
; CHECK-NEXT: mov w8, #9
15-
; CHECK-NEXT: mov w0, #1
16-
; CHECK-NEXT: str w8, [x8]
17-
; CHECK-NEXT: ret
18-
; CHECK-NEXT: .p2align 4
19-
; CHECK-NEXT: LBB0_2: ; %bb1
20-
; CHECK-NEXT: mov w8, #42
21-
; CHECK-NEXT: mov w0, wzr
22-
; CHECK-NEXT: str w8, [x8]
23-
; CHECK-NEXT: ret
7+
; CHECK: b.eq [[JUMP_BB1:LBB[0-9]+_[0-9]+]]
8+
; CHECK-NEXT: b [[JUMP_BB2:LBB[0-9]+_[0-9]+]]
9+
10+
; CHECK: [[JUMP_BB1]]:
11+
; CHECK: ret
12+
; CHECK: .p2align 4
13+
14+
; CHECK: [[JUMP_BB2]]:
15+
; CHECK: ret
16+
define i32 @invert_bcc_block_align_higher_func(i32 %x, i32 %y) align 4 #0 {
2417
%1 = icmp eq i32 %x, %y
2518
br i1 %1, label %bb1, label %bb2
2619

0 commit comments

Comments
 (0)