[PATCH] D107810: [ARM] Improve detection of fallthough when aligning blocks

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 10 03:20:50 PDT 2021


dmgreen created this revision.
dmgreen added reviewers: samtebbs, SjoerdMeijer, NickGuy, ostannard, simon_tatham.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
dmgreen requested review of this revision.
Herald added a project: LLVM.

We align non-fallthrough branches under Cortex-M at O3 <https://reviews.llvm.org/owners/package/3/> to lead to fewer instruction fetches. This improves that for the block after a LE or LETP. These blocks will still have branches on until the LowOverheadLoops pass is run (as they are not handled by analyzeBranch, the branch is not removed until later), so canFallThrough will return false. These extra branches will eventually be removed, leaving a fallthrough, so treat them as such and don't add unnecessary alignments.


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
@@ -357,7 +357,7 @@
       Changed = true;
       MBB.setAlignment(Alignment);
     }
-    PrevCanFallthough = MBB.canFallThrough();
+    PrevCanFallthough = is_contained(MBB.successors(), MBB.getNextNode());
   }
 
   return Changed;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107810.365402.patch
Type: text/x-patch
Size: 1201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210810/d80d2b84/attachment.bin>


More information about the llvm-commits mailing list