Skip to content

Commit 72cb88f

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:d896b1f5a614 into amd-gfx:741a0a2ce1bd
Local branch amd-gfx 741a0a2 Merged main:d9962c400f97 into amd-gfx:8bf360256d7b Remote branch main d896b1f [PowerPC] Do not string pool globals that are part of llvm used. (llvm#66848)
2 parents 741a0a2 + d896b1f commit 72cb88f

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 481678
19+
#define LLVM_MAIN_REVISION 481680
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ bool CombinerHelper::matchShiftImmedChain(MachineInstr &MI,
15571557

15581558
// Pass the combined immediate to the apply function.
15591559
MatchInfo.Imm =
1560-
(MaybeImmVal->Value.getSExtValue() + MaybeImm2Val->Value).getSExtValue();
1560+
(MaybeImmVal->Value.getZExtValue() + MaybeImm2Val->Value).getZExtValue();
15611561
MatchInfo.Reg = Base;
15621562

15631563
// There is no simple replacement for a saturating unsigned left shift that

llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ static bool hasReplaceableUsers(GlobalVariable &GV) {
140140
// valid candidates to be merged into the string pool. Valid candidates will
141141
// be added to MergeableStrings.
142142
void PPCMergeStringPool::collectCandidateConstants(Module &M) {
143+
SmallVector<GlobalValue *, 4> UsedV;
144+
collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/false);
145+
SmallVector<GlobalValue *, 4> UsedVCompiler;
146+
collectUsedGlobalVariables(M, UsedVCompiler, /*CompilerUsed=*/true);
147+
// Combine all of the Global Variables marked as used into a SmallPtrSet for
148+
// faster lookup inside the loop.
149+
SmallPtrSet<GlobalValue *, 8> AllUsedGlobals;
150+
AllUsedGlobals.insert(UsedV.begin(), UsedV.end());
151+
AllUsedGlobals.insert(UsedVCompiler.begin(), UsedVCompiler.end());
152+
143153
for (GlobalVariable &Global : M.globals()) {
144154
LLVM_DEBUG(dbgs() << "Looking at global:");
145155
LLVM_DEBUG(Global.dump());
@@ -171,6 +181,10 @@ void PPCMergeStringPool::collectCandidateConstants(Module &M) {
171181
if (!ConstData)
172182
continue;
173183

184+
// Do not pool globals that are part of llvm.used or llvm.compiler.end.
185+
if (AllUsedGlobals.contains(&Global))
186+
continue;
187+
174188
if (!hasReplaceableUsers(Global))
175189
continue;
176190

llvm/test/CodeGen/AArch64/GlobalISel/prelegalizercombiner-trivial-arith.mir

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,28 @@ body: |
463463
RET_ReallyLR implicit $x0
464464
465465
...
466+
---
467+
name: udiv_of_sext
468+
alignment: 4
469+
tracksRegLiveness: true
470+
liveins:
471+
- { reg: '$w0' }
472+
body: |
473+
bb.1:
474+
liveins: $w0
475+
476+
; CHECK-LABEL: name: udiv_of_sext
477+
; CHECK: liveins: $w0
478+
; CHECK-NEXT: {{ $}}
479+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
480+
; CHECK-NEXT: $w0 = COPY [[C]](s32)
481+
; CHECK-NEXT: RET_ReallyLR implicit $w0
482+
%2:_(s1) = G_CONSTANT i1 true
483+
%4:_(s2) = G_CONSTANT i2 1
484+
%3:_(s2) = G_SEXT %2:_(s1)
485+
%5:_(s2) = G_UDIV %4:_, %3:_
486+
%6:_(s32) = G_ANYEXT %5:_(s2)
487+
$w0 = COPY %6:_(s32)
488+
RET_ReallyLR implicit $w0
489+
490+
...
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
;; Test that the string pooling pass does not pool globals that are
2+
;; in llvm.used or in llvm.compiler.used.
3+
4+
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc-ibm-aix-xcoff -data-sections=false < %s | \
5+
; RUN: FileCheck %s
6+
7+
; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64-ibm-aix-xcoff -data-sections=false < %s | \
8+
; RUN: FileCheck %s
9+
10+
@keep_this = internal constant [5 x i8] c"keep1", align 1
11+
@keep_this2 = internal constant [5 x i8] c"keep2", align 1
12+
@.str.1 = private unnamed_addr constant [12 x i8] c"str1_STRING\00", align 1
13+
@.str.2 = private unnamed_addr constant [12 x i8] c"str2_STRING\00", align 1
14+
@.str.3 = private unnamed_addr constant [12 x i8] c"str3_STRING\00", align 1
15+
@llvm.used = appending global [1 x ptr] [ptr @keep_this], section "llvm.metadata"
16+
@llvm.compiler.used = appending global [1 x ptr] [ptr @keep_this2], section "llvm.metadata"
17+
18+
declare signext i32 @callee(ptr noundef)
19+
20+
define dso_local signext i32 @keep1() {
21+
entry:
22+
%call = tail call signext i32 @callee(ptr noundef nonnull @keep_this)
23+
ret i32 %call
24+
}
25+
26+
define dso_local signext i32 @keep2() {
27+
entry:
28+
%call = tail call signext i32 @callee(ptr noundef nonnull @keep_this2)
29+
ret i32 %call
30+
}
31+
32+
define dso_local signext i32 @str1() {
33+
entry:
34+
%call = tail call signext i32 @callee(ptr noundef nonnull @.str.1)
35+
ret i32 %call
36+
}
37+
38+
define dso_local signext i32 @str2() {
39+
entry:
40+
%call = tail call signext i32 @callee(ptr noundef nonnull @.str.2)
41+
ret i32 %call
42+
}
43+
44+
define dso_local signext i32 @str3() {
45+
entry:
46+
%call = tail call signext i32 @callee(ptr noundef nonnull @.str.3)
47+
ret i32 %call
48+
}
49+
50+
; CHECK: .lglobl keep_this
51+
; CHECK: keep_this:
52+
; CHECK: .lglobl keep_this2
53+
; CHECK: keep_this2:
54+
; CHECK: L..__ModuleStringPool:
55+
; CHECK: .string "str1_STRING"
56+
; CHECK: .string "str2_STRING"
57+
; CHECK: .string "str3_STRING"

0 commit comments

Comments
 (0)