Skip to content

Commit a65867a

Browse files
[BOLT][AArch64] Fix search to proceed upwards from memcpy call (#166182)
The search should proceed from CallInst to the beginning of BB since X2 can be rewritten and we need to catch the most recent write before the call. Patch by Yafet Beyene alulayafet@gmail.com
1 parent 86d9e1c commit a65867a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2804,7 +2804,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
28042804
BitVector WrittenRegs(RegInfo->getNumRegs());
28052805
const BitVector &SizeRegAliases = getAliases(SizeReg);
28062806

2807-
for (auto InstIt = BB.begin(); InstIt != CallInst; ++InstIt) {
2807+
for (auto InstIt = CallInst; InstIt != BB.begin(); --InstIt) {
28082808
const MCInst &Inst = *InstIt;
28092809
WrittenRegs.reset();
28102810
getWrittenRegs(Inst, WrittenRegs);

bolt/test/runtime/AArch64/inline-memcpy.s

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# RUN: llvm-bolt %t.exe --inline-memcpy -o %t.bolt 2>&1 | FileCheck %s --check-prefix=CHECK-INLINE
88
# RUN: llvm-objdump -d %t.bolt | FileCheck %s --check-prefix=CHECK-ASM
99

10-
# Verify BOLT reports that it inlined memcpy calls (11 successful inlines out of 16 total calls)
10+
# Verify BOLT reports that it inlined memcpy calls (11 successful inlines out of 17 total calls)
1111
# CHECK-INLINE: BOLT-INFO: inlined 11 memcpy() calls
1212

1313
# Each function should use optimal size-specific instructions and NO memcpy calls
@@ -84,6 +84,9 @@
8484
# CHECK-ASM-LABEL: <test_register_move_negative>:
8585
# CHECK-ASM: bl{{.*}}<memcpy
8686

87+
# CHECK-ASM-LABEL: <test_x2_rewrite_negative>:
88+
# CHECK-ASM: bl{{.*}}<memcpy
89+
8790
# Live-in parameter should NOT be inlined (size unknown at compile time)
8891
# CHECK-ASM-LABEL: <test_live_in_negative>:
8992
# CHECK-ASM: bl{{.*}}<memcpy
@@ -273,6 +276,15 @@ test_register_move_negative:
273276
ret
274277
.size test_register_move_negative, .-test_register_move_negative
275278

279+
.globl test_x2_rewrite_negative
280+
.type test_x2_rewrite_negative,@function
281+
test_x2_rewrite_negative:
282+
mov x2, #8
283+
ldr x2, [sp, #24]
284+
bl memcpy
285+
ret
286+
.size test_x2_rewrite_negative, .-test_x2_rewrite_negative
287+
276288
.globl test_live_in_negative
277289
.type test_live_in_negative,@function
278290
test_live_in_negative:

0 commit comments

Comments
 (0)