Skip to content

Commit 61ab106

Browse files
committed
[RISCV] Add tune features of preferred function/loop align
D144048 has added preferred function and loop alignment to RISCVSubtarget, but now we need to set them manually for different processors. Tune features that set preferred function/loop align to [2, 64] bytes (align 1 is not here since the min align is 2) are added. These features can be used in processor definitions. Reviewed By: asb Differential Revision: https://reviews.llvm.org/D157832
1 parent 2b2889b commit 61ab106

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,12 @@ def FeatureTaggedGlobals : SubtargetFeature<"tagged-globals",
925925
"AllowTaggedGlobals",
926926
"true", "Use an instruction sequence for taking the address of a global "
927927
"that allows a memory tag in the upper address bits">;
928+
929+
foreach align = [2, 4, 8, 16, 32, 64] in {
930+
def TunePrefFunctionAlignment # align :
931+
SubtargetFeature<"pref-func-align-" # align, "PrefFunctionAlignment",
932+
"Align(" # align # ")", "Set preferred function alignment to " # align # " bytes">;
933+
def TunePrefLoopAlignment # align :
934+
SubtargetFeature<"pref-loop-align-" # align, "PrefLoopAlignment",
935+
"Align(" # align # ")", "Set preferred loop alignment to " # align # " bytes">;
936+
}

llvm/test/CodeGen/RISCV/align-loops.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; RUN: llc < %s -mtriple=riscv64 | FileCheck %s
22
; RUN: llc < %s -mtriple=riscv64 -align-loops=16 | FileCheck %s -check-prefix=ALIGN_16
33
; RUN: llc < %s -mtriple=riscv64 -align-loops=32 | FileCheck %s -check-prefix=ALIGN_32
4+
; RUN: llc < %s -mtriple=riscv64 -mattr=+pref-loop-align-16 | FileCheck %s -check-prefix=ALIGN_16
5+
; RUN: llc < %s -mtriple=riscv64 -mattr=+pref-loop-align-32 | FileCheck %s -check-prefix=ALIGN_32
46

57
declare void @foo()
68

llvm/test/CodeGen/RISCV/align.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
; RUN: | FileCheck %s -check-prefix=RV32I
33
; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs < %s \
44
; RUN: | FileCheck %s -check-prefix=RV32C
5+
; RUN: llc -mtriple=riscv32 -mattr=+pref-func-align-32 -verify-machineinstrs < %s \
6+
; RUN: | FileCheck %s -check-prefix=ALIGN-32
57
; RUN: llc -filetype=obj -mtriple=riscv32 < %s -o %t
68
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefixes=SEC,SEC-I
79
; RUN: llc -filetype=obj -mtriple=riscv32 -mattr=+c < %s -o %t
@@ -16,6 +18,8 @@ define void @foo() {
1618
;RV32I: foo:
1719
;RV32C: .p2align 1
1820
;RV32C: foo:
21+
;ALIGN-32: .p2align 5
22+
;ALIGN-32: foo:
1923
entry:
2024
ret void
2125
}

0 commit comments

Comments
 (0)