Skip to content

Commit 6210f27

Browse files
author
Ana Pazos
committedAug 18, 2017
[PGO] Fixed assertion due to mismatched memcpy size type.
Summary: Memcpy intrinsics have size argument of any integer type, like i32 or i64. Fixed size type along with its value when cloning the intrinsic. Reviewers: davidxl, xur Reviewed By: davidxl Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D36844 llvm-svn: 311188
1 parent 14302fc commit 6210f27

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed
 

‎llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,15 @@ bool MemOPSizeOpt::perform(MemIntrinsic *MI) {
361361
DEBUG(dbgs() << "\n\n== Basic Block After==\n");
362362

363363
for (uint64_t SizeId : SizeIds) {
364-
ConstantInt *CaseSizeId = ConstantInt::get(Type::getInt64Ty(Ctx), SizeId);
365364
BasicBlock *CaseBB = BasicBlock::Create(
366365
Ctx, Twine("MemOP.Case.") + Twine(SizeId), &Func, DefaultBB);
367366
Instruction *NewInst = MI->clone();
368367
// Fix the argument.
369-
dyn_cast<MemIntrinsic>(NewInst)->setLength(CaseSizeId);
368+
MemIntrinsic * MemI = dyn_cast<MemIntrinsic>(NewInst);
369+
IntegerType *SizeType = dyn_cast<IntegerType>(MemI->getLength()->getType());
370+
assert(SizeType && "Expected integer type size argument.");
371+
ConstantInt *CaseSizeId = ConstantInt::get(SizeType, SizeId);
372+
MemI->setLength(CaseSizeId);
370373
CaseBB->getInstList().push_back(NewInst);
371374
IRBuilder<> IRBCase(CaseBB);
372375
IRBCase.CreateBr(MergeBB);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt < %s -pgo-memop-opt -S | FileCheck %s
2+
3+
define i32 @test(i8* %a, i8* %b) !prof !1 {
4+
; CHECK_LABEL: test
5+
; CHECK: MemOP.Case.3:
6+
; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %a, i32 3, i32 1, i1 false)
7+
; CHECK: MemOP.Case.2:
8+
; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %a, i32 2, i32 1, i1 false)
9+
; CHECK: MemOP.Default:
10+
; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %a, i32 undef, i32 1, i1 false)
11+
; CHECK: MemOP.Case.33:
12+
; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* %b, i64 3, i32 1, i1 false)
13+
; CHECK MemOP.Case.24:
14+
; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* %b, i64 2, i32 1, i1 false)
15+
; CHECK: MemOP.Default2:
16+
; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* %b, i64 undef, i32 1, i1 false)
17+
tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %a, i32 undef, i32 1, i1 false), !prof !2
18+
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* %b, i64 undef, i32 1, i1 false), !prof !2
19+
unreachable
20+
}
21+
22+
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i1)
23+
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
24+
25+
!1 = !{!"function_entry_count", i64 5170}
26+
!2 = !{!"VP", i32 1, i64 2585, i64 3, i64 1802, i64 2, i64 783}
27+

0 commit comments

Comments
 (0)
Please sign in to comment.