Skip to content

Commit 9e92588

Browse files
committed
Review comments
- Removed handling of global variable destinations. We simply don't pad these for now - Added check that destination array is an array type and added test. Change-Id: Ifc53051952ef69c4af64827402baf7d69cab4824
1 parent e1218a0 commit 9e92588

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,15 +2043,18 @@ static bool callInstIsMemcpy(CallInst *CI) {
20432043
}
20442044

20452045
static bool destArrayCanBeWidened(CallInst *CI) {
2046-
auto *Alloca = dyn_cast<AllocaInst>(CI->getArgOperand(0));
20472046
auto *IsVolatile = dyn_cast<ConstantInt>(CI->getArgOperand(3));
2047+
auto *Alloca = dyn_cast<AllocaInst>(CI->getArgOperand(0));
20482048

20492049
if (!Alloca || !IsVolatile || IsVolatile->isOne())
20502050
return false;
20512051

20522052
if (!Alloca->isStaticAlloca())
20532053
return false;
20542054

2055+
if (!Alloca->getAllocatedType()->isArrayTy())
2056+
return false;
2057+
20552058
return true;
20562059
}
20572060

@@ -2089,15 +2092,8 @@ static void widenDestArray(CallInst *CI, const unsigned NumBytesToPad,
20892092
const unsigned NumBytesToCopy,
20902093
ConstantDataArray *SourceDataArray) {
20912094

2092-
// Dest array can be global or local
2093-
auto *DestGV = dyn_cast<GlobalVariable>(CI->getArgOperand(0));
20942095
auto *Alloca = dyn_cast<AllocaInst>(CI->getArgOperand(0));
2095-
if (DestGV) {
2096-
auto *F = CI->getCalledFunction();
2097-
auto *NewDestGV =
2098-
widenGlobalVariable(DestGV, F, NumBytesToPad, NumBytesToCopy);
2099-
DestGV->replaceAllUsesWith(NewDestGV);
2100-
} else if (Alloca) {
2096+
if (Alloca) {
21012097
unsigned ElementByteWidth = SourceDataArray->getElementByteSize();
21022098
unsigned int TotalBytes = NumBytesToCopy + NumBytesToPad;
21032099
unsigned NumElementsToCopy = divideCeil(TotalBytes, ElementByteWidth);
@@ -2130,7 +2126,7 @@ static bool tryWidenGlobalArrayAndDests(Function *F, GlobalVariable *SourceVar,
21302126
// are memcpys.
21312127
for (auto *User : SourceVar->users()) {
21322128
auto *CI = dyn_cast<CallInst>(User);
2133-
if (!callInstIsMemcpy(CI))
2129+
if (!callInstIsMemcpy(CI) || !destArrayCanBeWidened(CI))
21342130
continue;
21352131

21362132
if (CI->getArgOperand(1) != SourceVar)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
@.i8 = private unnamed_addr constant [3 x i8] [i8 1, i8 2, i8 3] , align 1
5+
6+
define void @memcpy_struct() {
7+
; CHECK-LABEL: define void @memcpy_struct() local_unnamed_addr {
8+
; CHECK-NEXT: [[ENTRY:.*:]]
9+
; CHECK-NEXT: [[SOMETHING:%.*]] = alloca { i8, i8, i8 }, align 1
10+
; CHECK-NEXT: [[CALL1:%.*]] = call i32 @bar(ptr nonnull [[SOMETHING]])
11+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) [[SOMETHING]], ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 3, i1 false)
12+
; CHECK-NEXT: ret void
13+
;
14+
entry:
15+
%something = alloca {i8, i8, i8}, align 1
16+
%call1 = call i32 @bar(ptr nonnull %something)
17+
call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) %something, ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 3, i1 false)
18+
ret void
19+
}
20+
21+
22+
@.i8_multi = private unnamed_addr constant [2 x [3 x i8]] [[3 x i8] [i8 1, i8 2, i8 3], [3 x i8] [i8 4, i8 5, i8 6]] , align 1
23+
24+
define void @memcpy_array_multidimensional() {
25+
; CHECK-LABEL: define void @memcpy_array_multidimensional() local_unnamed_addr {
26+
; CHECK-NEXT: [[ENTRY:.*:]]
27+
; CHECK-NEXT: [[SOMETHING:%.*]] = alloca [2 x [3 x i8]], align 1
28+
; CHECK-NEXT: [[CALL1:%.*]] = call i32 @bar(ptr nonnull [[SOMETHING]])
29+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) [[SOMETHING]], ptr noundef nonnull align 1 dereferenceable(3) @.i8_multi, i32 3, i1 false)
30+
; CHECK-NEXT: ret void
31+
;
32+
entry:
33+
%something = alloca [2 x [3 x i8]], align 1
34+
%call1 = call i32 @bar(ptr nonnull %something)
35+
call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) %something, ptr noundef nonnull align 1 dereferenceable(3) @.i8_multi, i32 3, i1 false)
36+
ret void
37+
}
38+
39+
declare i32 @bar(...)

llvm/test/Transforms/GlobalOpt/ARM/arm-widen-global-dest.ll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
; 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
2+
; RUN: opt < %s -mtriple=arm-none-eabi -passes=globalopt -S | FileCheck %s
33

4-
@.i8 = private unnamed_addr constant [3 x i8] [i8 1, i8 2, i8 3] , align 1
4+
; CHECK: [3 x i8]
55
@other = private unnamed_addr global [3 x i8] [i8 1, i8 2, i8 3] , align 1
6+
; CHECK: [4 x i8]
7+
@.i8 = private unnamed_addr constant [3 x i8] [i8 1, i8 2, i8 3] , align 1
68

79
define void @memcpy_multiple() {
810
; CHECK-LABEL: define void @memcpy_multiple() local_unnamed_addr {
911
; CHECK-NEXT: [[ENTRY:.*:]]
1012
; CHECK-NEXT: [[SOMETHING:%.*]] = alloca [4 x i8], align 1
11-
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) [[SOMETHING]], ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 4, i1 false)
12-
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) @other, ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 4, i1 false)
1313
; CHECK-NEXT: [[CALL2:%.*]] = call i32 @bar(ptr nonnull [[SOMETHING]])
14+
; CHECK-NEXT: [[CALL3:%.*]] = call i32 @bar(ptr nonnull @other)
15+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) @other, ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 3, i1 false)
16+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) [[SOMETHING]], ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 4, i1 false)
1417
; CHECK-NEXT: ret void
1518
;
1619
entry:
1720
%something = alloca [3 x i8], align 1
18-
call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) %something, ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 3, i1 false)
21+
%call1 = call i32 @bar(ptr nonnull %something)
22+
%call2 = call i32 @bar(ptr nonnull @other)
1923
call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) @other, ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 3, i1 false)
20-
%call2 = call i32 @bar(ptr nonnull %something)
24+
call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(3) %something, ptr noundef nonnull align 1 dereferenceable(3) @.i8, i32 3, i1 false)
2125
ret void
2226
}
2327

0 commit comments

Comments
 (0)