Skip to content

Commit 75f951a

Browse files
committed
Responding to review comments
- Added test showing behaviour of attempting to widen non-const globals - Refactoring Change-Id: I566214331bf3d889bd1409d3148aa6eab2530ed5
1 parent 2815d59 commit 75f951a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,10 +2113,6 @@ static bool tryWidenGlobalArrayAndDests(Function *F, GlobalVariable *SourceVar,
21132113
const unsigned NumBytesToCopy,
21142114
ConstantInt *BytesToCopyOp,
21152115
ConstantDataArray *SourceDataArray) {
2116-
if (!SourceVar->hasInitializer() || !SourceVar->isConstant() ||
2117-
!SourceVar->hasLocalLinkage() || !SourceVar->hasGlobalUnnamedAddr())
2118-
return false;
2119-
21202116
auto *NewSourceGV =
21212117
widenGlobalVariable(SourceVar, F, NumBytesToPad, NumBytesToCopy);
21222118
if (!NewSourceGV)
@@ -2147,7 +2143,8 @@ static bool tryWidenGlobalArraysUsedByMemcpy(
21472143
GlobalVariable *GV,
21482144
function_ref<TargetTransformInfo &(Function &)> GetTTI) {
21492145

2150-
if (!GV->hasInitializer())
2146+
if (!GV->hasInitializer() || !GV->isConstant() || !GV->hasLocalLinkage() ||
2147+
!GV->hasGlobalUnnamedAddr())
21512148
return false;
21522149

21532150
for (auto *User : GV->users()) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -mtriple=arm-none-eabi -passes=globalopt -S | FileCheck %s
3+
4+
@.str = unnamed_addr global [3 x i8] c"12\00", align 1
5+
6+
define void @foo() {
7+
; CHECK-LABEL: define void @foo() local_unnamed_addr {
8+
; CHECK-NEXT: [[ENTRY:.*:]]
9+
; CHECK-NEXT: [[SOMETHING:%.*]] = alloca [3 x i8], align 1
10+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) [[SOMETHING]], ptr noundef nonnull align 1 dereferenceable(3) @.str, i32 3, i1 false)
11+
; CHECK-NEXT: [[CALL1:%.*]] = call i32 @bar(ptr nonnull [[SOMETHING]])
12+
; CHECK-NEXT: ret void
13+
;
14+
entry:
15+
%something = alloca [3 x i8], align 1
16+
call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) %something, ptr noundef nonnull align 1 dereferenceable(3) @.str, i32 3, i1 false)
17+
%call1 = call i32 @bar(ptr nonnull %something)
18+
ret void
19+
}
20+
21+
declare i32 @bar(...)

0 commit comments

Comments
 (0)