Skip to content

Commit 4d65a22

Browse files
committed
[LTT] Add unknown branch weights when lowering type tests with conditional
1 parent 6a148c5 commit 4d65a22

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
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: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ define i1 @allones32(ptr %p) {
8585
ret i1 %x
8686
}
8787

88-
define i1 @bytearray7(ptr %p) {
88+
define i1 @bytearray7(ptr %p) !prof !0 {
8989
; X86-LABEL: define i1 @bytearray7(
90-
; X86-SAME: ptr [[P:%.*]]) {
90+
; X86-SAME: ptr [[P:%.*]]) !prof [[PROF6:![0-9]+]] {
9191
; X86-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
9292
; X86-NEXT: [[TMP2:%.*]] = sub i64 ptrtoint (ptr @__typeid_bytearray7_global_addr to i64), [[TMP1]]
93-
; X86-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 ptrtoint (ptr @__typeid_bytearray7_align to i64))
94-
; X86-NEXT: [[TMP4:%.*]] = icmp ule i64 [[TMP3]], ptrtoint (ptr @__typeid_bytearray7_size_m1 to i64)
95-
; X86-NEXT: br i1 [[TMP4]], label [[TMP5:%.*]], label [[TMP10:%.*]]
93+
; X86-NEXT: [[TMP7:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 ptrtoint (ptr @__typeid_bytearray7_align to i64))
94+
; X86-NEXT: [[TMP8:%.*]] = icmp ule i64 [[TMP7]], ptrtoint (ptr @__typeid_bytearray7_size_m1 to i64)
95+
; X86-NEXT: br i1 [[TMP8]], label [[TMP5:%.*]], label [[TMP14:%.*]], !prof [[PROF7:![0-9]+]]
9696
; X86: 5:
9797
; X86-NEXT: [[TMP6:%.*]] = getelementptr i8, ptr @__typeid_bytearray7_byte_array, i64 [[TMP3]]
9898
; X86-NEXT: [[TMP7:%.*]] = load i8, ptr [[TMP6]], align 1
@@ -104,12 +104,12 @@ define i1 @bytearray7(ptr %p) {
104104
; X86-NEXT: ret i1 [[TMP11]]
105105
;
106106
; ARM-LABEL: define i1 @bytearray7(
107-
; ARM-SAME: ptr [[P:%.*]]) {
107+
; ARM-SAME: ptr [[P:%.*]]) !prof [[PROF0:![0-9]+]] {
108108
; ARM-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
109109
; ARM-NEXT: [[TMP2:%.*]] = sub i64 ptrtoint (ptr @__typeid_bytearray7_global_addr to i64), [[TMP1]]
110-
; ARM-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 3)
111-
; ARM-NEXT: [[TMP4:%.*]] = icmp ule i64 [[TMP3]], 43
112-
; ARM-NEXT: br i1 [[TMP4]], label [[TMP5:%.*]], label [[TMP10:%.*]]
110+
; ARM-NEXT: [[TMP5:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 3)
111+
; ARM-NEXT: [[TMP6:%.*]] = icmp ule i64 [[TMP5]], 43
112+
; ARM-NEXT: br i1 [[TMP6]], label [[TMP7:%.*]], label [[TMP12:%.*]], !prof [[PROF1:![0-9]+]]
113113
; ARM: 5:
114114
; ARM-NEXT: [[TMP6:%.*]] = getelementptr i8, ptr @__typeid_bytearray7_byte_array, i64 [[TMP3]]
115115
; ARM-NEXT: [[TMP7:%.*]] = load i8, ptr [[TMP6]], align 1
@@ -253,17 +253,31 @@ define i1 @single(ptr %p) {
253253
%x = call i1 @llvm.type.test(ptr %p, metadata !"single")
254254
ret i1 %x
255255
}
256+
257+
!0 = !{!"function_entry_count", i32 10}
258+
259+
; X86: !0 = !{i64 0, i64 256}
260+
; X86: !1 = !{i64 0, i64 64}
261+
; X86: !2 = !{i64 -1, i64 -1}
262+
; X86: !3 = !{i64 0, i64 32}
263+
; X86: !4 = !{i64 0, i64 4294967296}
264+
; X86: !5 = !{i64 0, i64 128}
256265
;.
257266
; X86: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
258267
; X86: attributes #[[ATTR1:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
259268
;.
269+
; ARM: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
270+
; ARM: attributes #[[ATTR1:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
271+
;.
260272
; X86: [[META0]] = !{i64 0, i64 256}
261273
; X86: [[META1]] = !{i64 0, i64 64}
262274
; X86: [[META2]] = !{i64 -1, i64 -1}
263275
; X86: [[META3]] = !{i64 0, i64 32}
264276
; X86: [[META4]] = !{i64 0, i64 4294967296}
265277
; X86: [[META5]] = !{i64 0, i64 128}
278+
; X86: [[PROF6]] = !{!"function_entry_count", i32 10}
279+
; X86: [[PROF7]] = !{!"unknown", !"lowertypetests"}
266280
;.
267-
; ARM: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
268-
; ARM: attributes #[[ATTR1:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
281+
; ARM: [[PROF0]] = !{!"function_entry_count", i32 10}
282+
; ARM: [[PROF1]] = !{!"unknown", !"lowertypetests"}
269283
;.

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)