Skip to content

Commit 48751a3

Browse files
committed
[LTT] Add unknown branch weights when lowering type tests with conditional
1 parent d63a01b commit 48751a3

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "llvm/IR/ModuleSummaryIndexYAML.h"
5555
#include "llvm/IR/Operator.h"
5656
#include "llvm/IR/PassManager.h"
57+
#include "llvm/IR/ProfDataUtils.h"
5758
#include "llvm/IR/ReplaceConstant.h"
5859
#include "llvm/IR/Type.h"
5960
#include "llvm/IR/Use.h"
@@ -803,6 +804,8 @@ Value *LowerTypeTestsModule::lowerTypeTestCall(Metadata *TypeId, CallInst *CI,
803804
}
804805

805806
IRBuilder<> ThenB(SplitBlockAndInsertIfThen(OffsetInRange, CI, false));
807+
setExplicitlyUnknownBranchWeightsIfProfiled(*InitialBB->getTerminator(),
808+
DEBUG_TYPE);
806809

807810
// Now that we know that the offset is in range and aligned, load the
808811
// appropriate bit from the bitset.

llvm/test/Transforms/LowerTypeTests/import.ll

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ define i1 @allones32(ptr %p) {
8686
ret i1 %x
8787
}
8888

89-
define i1 @bytearray7(ptr %p) {
89+
define i1 @bytearray7(ptr %p) !prof !0 {
9090
; X86-LABEL: define i1 @bytearray7(
91-
; X86-SAME: ptr [[P:%.*]]) {
91+
; X86-SAME: ptr [[P:%.*]]) !prof [[PROF6:![0-9]+]] {
9292
; X86-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
9393
; X86-NEXT: [[TMP2:%.*]] = sub i64 ptrtoint (ptr @__typeid_bytearray7_global_addr to i64), [[TMP1]]
9494
; X86-NEXT: [[TMP7:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 ptrtoint (ptr @__typeid_bytearray7_align to i64))
9595
; X86-NEXT: [[TMP8:%.*]] = icmp ule i64 [[TMP7]], ptrtoint (ptr @__typeid_bytearray7_size_m1 to i64)
96-
; X86-NEXT: br i1 [[TMP8]], label [[TMP5:%.*]], label [[TMP14:%.*]]
96+
; X86-NEXT: br i1 [[TMP8]], label [[TMP5:%.*]], label [[TMP14:%.*]], !prof [[PROF7:![0-9]+]]
9797
; X86: 5:
9898
; X86-NEXT: [[TMP10:%.*]] = getelementptr i8, ptr @__typeid_bytearray7_byte_array, i64 [[TMP7]]
9999
; X86-NEXT: [[TMP11:%.*]] = load i8, ptr [[TMP10]], align 1
@@ -105,12 +105,12 @@ define i1 @bytearray7(ptr %p) {
105105
; X86-NEXT: ret i1 [[TMP15]]
106106
;
107107
; ARM-LABEL: define i1 @bytearray7(
108-
; ARM-SAME: ptr [[P:%.*]]) {
108+
; ARM-SAME: ptr [[P:%.*]]) !prof [[PROF0:![0-9]+]] {
109109
; ARM-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
110110
; ARM-NEXT: [[TMP2:%.*]] = sub i64 ptrtoint (ptr @__typeid_bytearray7_global_addr to i64), [[TMP1]]
111111
; ARM-NEXT: [[TMP5:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 3)
112112
; ARM-NEXT: [[TMP6:%.*]] = icmp ule i64 [[TMP5]], 43
113-
; ARM-NEXT: br i1 [[TMP6]], label [[TMP7:%.*]], label [[TMP12:%.*]]
113+
; ARM-NEXT: br i1 [[TMP6]], label [[TMP7:%.*]], label [[TMP12:%.*]], !prof [[PROF1:![0-9]+]]
114114
; ARM: 5:
115115
; ARM-NEXT: [[TMP8:%.*]] = getelementptr i8, ptr @__typeid_bytearray7_byte_array, i64 [[TMP5]]
116116
; ARM-NEXT: [[TMP9:%.*]] = load i8, ptr [[TMP8]], align 1
@@ -255,6 +255,8 @@ define i1 @single(ptr %p) {
255255
ret i1 %x
256256
}
257257

258+
!0 = !{!"function_entry_count", i32 10}
259+
258260
; X86: !0 = !{i64 0, i64 256}
259261
; X86: !1 = !{i64 0, i64 64}
260262
; X86: !2 = !{i64 -1, i64 -1}
@@ -265,13 +267,18 @@ define i1 @single(ptr %p) {
265267
; X86: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
266268
; X86: attributes #[[ATTR1:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
267269
;.
270+
; ARM: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
271+
; ARM: attributes #[[ATTR1:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
272+
;.
268273
; X86: [[META0]] = !{i64 0, i64 256}
269274
; X86: [[META1]] = !{i64 0, i64 64}
270275
; X86: [[META2]] = !{i64 -1, i64 -1}
271276
; X86: [[META3]] = !{i64 0, i64 32}
272277
; X86: [[META4]] = !{i64 0, i64 4294967296}
273278
; X86: [[META5]] = !{i64 0, i64 128}
279+
; X86: [[PROF6]] = !{!"function_entry_count", i32 10}
280+
; X86: [[PROF7]] = !{!"unknown", !"lowertypetests"}
274281
;.
275-
; ARM: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
276-
; ARM: attributes #[[ATTR1:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
282+
; ARM: [[PROF0]] = !{!"function_entry_count", i32 10}
283+
; ARM: [[PROF1]] = !{!"unknown", !"lowertypetests"}
277284
;.

llvm/utils/profcheck-xfail.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ Transforms/LowerSwitch/do-not-handle-impossible-values.ll
493493
Transforms/LowerSwitch/feature.ll
494494
Transforms/LowerSwitch/fold-popular-case-to-unreachable-default.ll
495495
Transforms/LowerSwitch/pr59316.ll
496-
Transforms/LowerTypeTests/import.ll
497-
Transforms/LowerTypeTests/simple.ll
498496
Transforms/MergeFunc/2011-02-08-RemoveEqual.ll
499497
Transforms/MergeFunc/apply_function_attributes.ll
500498
Transforms/MergeFunc/call-and-invoke-with-ranges-attr.ll

0 commit comments

Comments
 (0)