Skip to content

Commit ff3dcd0

Browse files
authored
[GlobalOpt][profcheck] Mark as unknown the branch weights of global shrunk to boolean (#171530)
1 parent 0570cab commit ff3dcd0

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "llvm/IR/IntrinsicInst.h"
4848
#include "llvm/IR/Module.h"
4949
#include "llvm/IR/Operator.h"
50+
#include "llvm/IR/ProfDataUtils.h"
5051
#include "llvm/IR/Type.h"
5152
#include "llvm/IR/Use.h"
5253
#include "llvm/IR/User.h"
@@ -1308,8 +1309,10 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
13081309
Instruction *NSI;
13091310
if (IsOneZero)
13101311
NSI = new ZExtInst(NLI, LI->getType(), "", LI->getIterator());
1311-
else
1312+
else {
13121313
NSI = SelectInst::Create(NLI, OtherVal, InitVal, "", LI->getIterator());
1314+
setExplicitlyUnknownBranchWeightsIfProfiled(*NSI, DEBUG_TYPE);
1315+
}
13131316
NSI->takeName(LI);
13141317
// Since LI is split into two instructions, NLI and NSI both inherit the
13151318
// same DebugLoc

llvm/test/Transforms/GlobalOpt/disable-globals-aa.ll

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; RUN: opt -O2 -S %s | FileCheck %s --check-prefix=WITHGLOBALSAA
33
; RUN: opt -O2 -enable-global-analyses=0 -S %s | FileCheck %s --check-prefix=NOGLOBALSAA
44

55
@glb = internal global i8 0
66

7+
;.
8+
; WITHGLOBALSAA: @glb = internal unnamed_addr global i1 false
9+
;.
10+
; NOGLOBALSAA: @glb = internal unnamed_addr global i1 false
11+
;.
712
define i8 @f(ptr %ptr) {
813
; WITHGLOBALSAA-LABEL: @f(
914
; WITHGLOBALSAA-NEXT: store i8 1, ptr [[PTR:%.*]], align 1
@@ -22,17 +27,32 @@ define i8 @f(ptr %ptr) {
2227
ret i8 %r
2328
}
2429

25-
define i8 @dummy() {
30+
define i8 @dummy() !prof !0 {
2631
; WITHGLOBALSAA-LABEL: @dummy(
2732
; WITHGLOBALSAA-NEXT: [[VAL_B:%.*]] = load i1, ptr @glb, align 1
28-
; WITHGLOBALSAA-NEXT: [[VAL:%.*]] = select i1 [[VAL_B]], i8 2, i8 0
33+
; WITHGLOBALSAA-NEXT: [[VAL:%.*]] = select i1 [[VAL_B]], i8 2, i8 0, !prof [[PROF1:![0-9]+]]
2934
; WITHGLOBALSAA-NEXT: ret i8 [[VAL]]
3035
;
3136
; NOGLOBALSAA-LABEL: @dummy(
3237
; NOGLOBALSAA-NEXT: [[VAL_B:%.*]] = load i1, ptr @glb, align 1
33-
; NOGLOBALSAA-NEXT: [[VAL:%.*]] = select i1 [[VAL_B]], i8 2, i8 0
38+
; NOGLOBALSAA-NEXT: [[VAL:%.*]] = select i1 [[VAL_B]], i8 2, i8 0, !prof [[PROF1:![0-9]+]]
3439
; NOGLOBALSAA-NEXT: ret i8 [[VAL]]
3540
;
3641
%val = load i8, ptr @glb
3742
ret i8 %val
3843
}
44+
45+
!0 = !{!"function_entry_count", i32 10}
46+
;.
47+
; WITHGLOBALSAA: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, inaccessiblemem: none, target_mem0: none, target_mem1: none) }
48+
; WITHGLOBALSAA: attributes #[[ATTR1:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) }
49+
;.
50+
; NOGLOBALSAA: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none) }
51+
; NOGLOBALSAA: attributes #[[ATTR1:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) }
52+
;.
53+
; WITHGLOBALSAA: [[META0:![0-9]+]] = !{!"function_entry_count", i32 10}
54+
; WITHGLOBALSAA: [[PROF1]] = !{!"unknown", !"globalopt"}
55+
;.
56+
; NOGLOBALSAA: [[META0:![0-9]+]] = !{!"function_entry_count", i32 10}
57+
; NOGLOBALSAA: [[PROF1]] = !{!"unknown", !"globalopt"}
58+
;.

llvm/utils/profcheck-xfail.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ Transforms/GCOVProfiling/reset.ll
163163
Transforms/GCOVProfiling/split-indirectbr-critical-edges.ll
164164
Transforms/GCOVProfiling/three-element-mdnode.ll
165165
Transforms/GCOVProfiling/version.ll
166-
Transforms/GlobalOpt/disable-globals-aa.ll
167-
Transforms/GlobalOpt/global-demotion.ll
168-
Transforms/GlobalOpt/globalvar-code-model.ll
169-
Transforms/GlobalOpt/large-int-crash.ll
170-
Transforms/GlobalOpt/shrink-global-to-bool-check-debug.ll
171-
Transforms/GlobalOpt/shrink-global-to-bool-opaque-ptrs.ll
172166
Transforms/GVN/debugloc-load-select.ll
173167
Transforms/GVN/load-through-select-dbg.ll
174168
Transforms/GVN/opaque-ptr.ll

0 commit comments

Comments
 (0)