[llvm] d65fecc - [ARM] Set preferred function alignment

Nicholas Guy via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 09:33:34 PDT 2023


Author: Nicholas Guy
Date: 2023-08-16T17:31:21+01:00
New Revision: d65feccb126226e6f7805a01d759ca1c9ce28237

URL: https://github.com/llvm/llvm-project/commit/d65feccb126226e6f7805a01d759ca1c9ce28237
DIFF: https://github.com/llvm/llvm-project/commit/d65feccb126226e6f7805a01d759ca1c9ce28237.diff

LOG: [ARM] Set preferred function alignment

Aligning functions yields small performance gains on
embedded cores, moreso with numerous small function calls.
Similar to aligning loops, if the function can fit within
a single cache line then the performance overhead of
fetching more instructions can be limited.

Differential Revision: https://reviews.llvm.org/D157514

Added: 
    llvm/test/CodeGen/ARM/preferred-function-alignment.ll

Modified: 
    llvm/lib/Target/ARM/ARMISelLowering.cpp
    llvm/lib/Target/ARM/ARMSubtarget.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index cd220239e9d03a..80a1476660947e 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -1612,6 +1612,7 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM,
   PredictableSelectIsExpensive = Subtarget->getSchedModel().isOutOfOrder();
 
   setPrefLoopAlignment(Align(1ULL << Subtarget->getPrefLoopLogAlignment()));
+  setPrefFunctionAlignment(Align(1ULL << Subtarget->getPrefLoopLogAlignment()));
 
   setMinFunctionAlignment(Subtarget->isThumb() ? Align(2) : Align(4));
 

diff  --git a/llvm/lib/Target/ARM/ARMSubtarget.h b/llvm/lib/Target/ARM/ARMSubtarget.h
index 715b5bee6dc606..eb5bf25f2a3826 100644
--- a/llvm/lib/Target/ARM/ARMSubtarget.h
+++ b/llvm/lib/Target/ARM/ARMSubtarget.h
@@ -198,7 +198,7 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
   /// operand cycle returned by the itinerary data for pre-ISel operands.
   int PreISelOperandLatencyAdjustment = 2;
 
-  /// What alignment is preferred for loop bodies, in log2(bytes).
+  /// What alignment is preferred for loop bodies and functions, in log2(bytes).
   unsigned PrefLoopLogAlignment = 0;
 
   /// The cost factor for MVE instructions, representing the multiple beats an

diff  --git a/llvm/test/CodeGen/ARM/preferred-function-alignment.ll b/llvm/test/CodeGen/ARM/preferred-function-alignment.ll
new file mode 100644
index 00000000000000..afe64a22c5e808
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/preferred-function-alignment.ll
@@ -0,0 +1,23 @@
+; RUN: llc -mtriple=arm-none-eabi -mcpu=cortex-m85 < %s | FileCheck --check-prefixes=CHECK,ALIGN-16,ALIGN-CS-16 %s
+; RUN: llc -mtriple=arm-none-eabi -mcpu=cortex-m23 < %s | FileCheck --check-prefixes=CHECK,ALIGN-16,ALIGN-CS-16 %s
+
+; RUN: llc -mtriple=arm-none-eabi -mcpu=cortex-a5 < %s  | FileCheck --check-prefixes=CHECK,ALIGN-32,ALIGN-CS-32 %s
+; RUN: llc -mtriple=arm-none-eabi -mcpu=cortex-m33 < %s | FileCheck --check-prefixes=CHECK,ALIGN-32,ALIGN-CS-16 %s
+; RUN: llc -mtriple=arm-none-eabi -mcpu=cortex-m55 < %s | FileCheck --check-prefixes=CHECK,ALIGN-32,ALIGN-CS-16 %s
+
+
+; CHECK-LABEL: test
+; ALIGN-16: .p2align 1
+; ALIGN-32: .p2align 2
+
+define void @test() {
+  ret void
+}
+
+; CHECK-LABEL: test_optsize
+; ALIGN-CS-16: .p2align 1
+; ALIGN-CS-32: .p2align 2
+
+define void @test_optsize() optsize {
+  ret void
+}


        


More information about the llvm-commits mailing list