Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit f1b37fe

Browse files
committed
Merging r329761:
------------------------------------------------------------------------ r329761 | gberry | 2018-04-10 14:43:03 -0700 (Tue, 10 Apr 2018) | 13 lines [AArch64][Falkor] Fix bug in Falkor HWPF collision avoidance pass. Summary: When inserting MOVs to avoid Falkor HWPF collisions, the non-base register operand of load instructions (e.g. a register offset) was not being considered live, so it could potentially have been used as a scratch register, clobbering the actual offset value. Reviewers: mcrosier Subscribers: rengolin, javed.absar, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D45502 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@330209 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0b57b47 commit f1b37fe

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/Target/AArch64/AArch64FalkorHWPFFix.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "llvm/Pass.h"
4747
#include "llvm/Support/Casting.h"
4848
#include "llvm/Support/Debug.h"
49+
#include "llvm/Support/DebugCounter.h"
4950
#include "llvm/Support/raw_ostream.h"
5051
#include <cassert>
5152
#include <iterator>
@@ -60,6 +61,8 @@ STATISTIC(NumCollisionsAvoided,
6061
"Number of HW prefetch tag collisions avoided");
6162
STATISTIC(NumCollisionsNotAvoided,
6263
"Number of HW prefetch tag collisions not avoided due to lack of regsiters");
64+
DEBUG_COUNTER(FixCounter, "falkor-hwpf",
65+
"Controls which tag collisions are avoided");
6366

6467
namespace {
6568

@@ -729,6 +732,21 @@ void FalkorHWPFFix::runOnLoop(MachineLoop &L, MachineFunction &Fn) {
729732
bool Fixed = false;
730733
DEBUG(dbgs() << "Attempting to fix tag collision: " << MI);
731734

735+
if (!DebugCounter::shouldExecute(FixCounter)) {
736+
DEBUG(dbgs() << "Skipping fix due to debug counter:\n " << MI);
737+
continue;
738+
}
739+
740+
// Add the non-base registers of MI as live so we don't use them as
741+
// scratch registers.
742+
for (unsigned OpI = 0, OpE = MI.getNumOperands(); OpI < OpE; ++OpI) {
743+
if (OpI == static_cast<unsigned>(LdI.BaseRegIdx))
744+
continue;
745+
MachineOperand &MO = MI.getOperand(OpI);
746+
if (MO.isReg() && MO.readsReg())
747+
LR.addReg(MO.getReg());
748+
}
749+
732750
for (unsigned ScratchReg : AArch64::GPR64RegClass) {
733751
if (!LR.available(ScratchReg) || MRI.isReserved(ScratchReg))
734752
continue;

test/CodeGen/AArch64/falkor-hwpf-fix.mir

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,28 @@ body: |
353353
bb.1:
354354
RET_ReallyLR
355355
...
356+
---
357+
# Check that non-base registers are considered live when finding a
358+
# scratch register by making sure we don't use %x2 for the scratch
359+
# register for the inserted ORRXrs.
360+
# CHECK-LABEL: name: hwpf_offreg
361+
# CHECK: %x3 = ORRXrs %xzr, %x1, 0
362+
# CHECK: %w10 = LDRWroX %x3, %x2, 0, 0
363+
name: hwpf_offreg
364+
tracksRegLiveness: true
365+
body: |
366+
bb.0:
367+
liveins: %w0, %x1, %x2, %x17, %x18
368+
369+
%w10 = LDRWroX %x1, %x2, 0, 0 :: ("aarch64-strided-access" load 4)
370+
371+
%x2 = ORRXrs %xzr, %x10, 0
372+
%w26 = LDRWroX %x1, %x2, 0, 0
373+
374+
%w0 = SUBWri %w0, 1, 0
375+
%wzr = SUBSWri %w0, 0, 0, implicit-def %nzcv
376+
Bcc 9, %bb.0, implicit %nzcv
377+
378+
bb.1:
379+
RET_ReallyLR
380+
...

0 commit comments

Comments
 (0)