[PATCH] D107810: [ARM] Improve detection of fallthough when aligning blocks
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 27 03:21:37 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb2d23dcd471: [ARM] Improve detection of fallthough when aligning blocks (authored by dmgreen).
Changed prior to commit:
https://reviews.llvm.org/D107810?vs=370927&id=375190#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107810/new/
https://reviews.llvm.org/D107810
Files:
llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
llvm/test/CodeGen/Thumb2/aligned-nonfallthrough.ll
Index: llvm/test/CodeGen/Thumb2/aligned-nonfallthrough.ll
===================================================================
--- llvm/test/CodeGen/Thumb2/aligned-nonfallthrough.ll
+++ llvm/test/CodeGen/Thumb2/aligned-nonfallthrough.ll
@@ -14,7 +14,6 @@
; CHECK-NEXT: ldr r2, [r0], #4
; CHECK-NEXT: add r1, r2
; CHECK-NEXT: le lr, .LBB0_1
-; CHECK-NEXT: .p2align 2
; CHECK-NEXT: @ %bb.2: @ %for.cond.cleanup
; CHECK-NEXT: mov r0, r1
; CHECK-NEXT: pop {r7, pc}
@@ -54,7 +53,6 @@
; CHECK-NEXT: ldr r2, [r12], #4
; CHECK-NEXT: smlal r0, r3, r2, r1
; CHECK-NEXT: le lr, .LBB1_2
-; CHECK-NEXT: .p2align 2
; CHECK-NEXT: @ %bb.3: @ %for.cond.cleanup
; CHECK-NEXT: mov r1, r3
; CHECK-NEXT: pop {r7, pc}
Index: llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
===================================================================
--- llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
+++ llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
@@ -18,6 +18,7 @@
#include "ARMMachineFunctionInfo.h"
#include "ARMSubtarget.h"
#include "MCTargetDesc/ARMBaseInfo.h"
+#include "MVETailPredUtils.h"
#include "Thumb2InstrInfo.h"
#include "Utils/ARMBaseInfo.h"
#include "llvm/ADT/DenseMap.h"
@@ -340,12 +341,12 @@
// Align blocks where the previous block does not fall through. This may add
// extra NOP's but they will not be executed. It uses the PrefLoopAlignment as a
// measure of how much to align, and only runs at CodeGenOpt::Aggressive.
-static bool AlignBlocks(MachineFunction *MF) {
+static bool AlignBlocks(MachineFunction *MF, const ARMSubtarget *STI) {
if (MF->getTarget().getOptLevel() != CodeGenOpt::Aggressive ||
MF->getFunction().hasOptSize())
return false;
- auto *TLI = MF->getSubtarget().getTargetLowering();
+ auto *TLI = STI->getTargetLowering();
const Align Alignment = TLI->getPrefLoopAlignment();
if (Alignment < 4)
return false;
@@ -357,7 +358,25 @@
Changed = true;
MBB.setAlignment(Alignment);
}
+
PrevCanFallthough = MBB.canFallThrough();
+
+ // For LOB's, the ARMLowOverheadLoops pass may remove the unconditional
+ // branch later in the pipeline.
+ if (STI->hasLOB()) {
+ for (const auto &MI : reverse(MBB.terminators())) {
+ if (MI.getOpcode() == ARM::t2B &&
+ MI.getOperand(0).getMBB() == MBB.getNextNode())
+ continue;
+ if (isLoopStart(MI) || MI.getOpcode() == ARM::t2LoopEnd ||
+ MI.getOpcode() == ARM::t2LoopEndDec) {
+ PrevCanFallthough = true;
+ break;
+ }
+ // Any other terminator - nothing to do
+ break;
+ }
+ }
}
return Changed;
@@ -406,7 +425,7 @@
}
// Align any non-fallthrough blocks
- MadeChange |= AlignBlocks(MF);
+ MadeChange |= AlignBlocks(MF, STI);
// Perform the initial placement of the constant pool entries. To start with,
// we put them all at the end of the function.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107810.375190.patch
Type: text/x-patch
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210927/a4348c46/attachment.bin>
More information about the llvm-commits
mailing list