From e544b4169062c23d364a6d9f519d0854645114bf Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Tue, 3 Apr 2018 12:21:02 -0700 Subject: [PATCH] Bug fix: unconditional branch should break the single dmb effect for adjacent stores --- .../AArch64/AArch64LoadStoreOptimizer.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp b/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp index 202b19525e1..b783b15d988 100644 --- a/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp +++ b/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp @@ -1597,6 +1597,30 @@ static bool isLoad(MachineInstr* MI) { } } +static bool isBranch(MachineInstr* MI) { + switch (MI->getOpcode()) { + default: { return false; } + case AArch64::B: + case AArch64::BR: + case AArch64::Bcc: + case AArch64::CBZW: + case AArch64::CBZX: + case AArch64::CBNZW: + case AArch64::CBNZX: + case AArch64::TBZW: + case AArch64::TBZX: + case AArch64::TBNZW: + case AArch64::TBNZX: + case AArch64::BLR: + case AArch64::BL: +// case AArch64::BX: +// case AArch64::BLX: + { + return true; + } + } +} + bool AArch64LoadStoreOpt::optimizeBlock(MachineBasicBlock &MBB, bool enableNarrowLdOpt) { // XXX-update: Try to add a 'dmb ld' fence before a relaxed store in the form @@ -1666,7 +1690,7 @@ bool AArch64LoadStoreOpt::optimizeBlock(MachineBasicBlock &MBB, DEBUG(dbgs() << "Added barrier instruction\n\t" << *DMBInst << "\n\tfor " << *MI << "\n"); // Skip all the way till we reach the end of the basic block or a load. - while (MBBI != E && !isLoad(&*MBBI)) { + while (MBBI != E && !isLoad(&*MBBI) && !isBranch(MBBI)) { MBBI++; } break; -- 2.34.1