[PATCH] D106570: [RISCV] Add backend command line options to control function and loop alignment for testing.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 22 09:44:31 PDT 2021


craig.topper created this revision.
craig.topper added reviewers: asb, evandro, luismarques, HsiangKai, khchen, arcbbb.
Herald added subscribers: StephenFan, vkmr, frasercrmck, apazos, sameer.abuasal, pengfei, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
craig.topper requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.

Clang doesn't support -falign-loops or -falign-functions. This
patch adds backend options to emulate them for testing. The
names were copied from x86. In the future we may want subtarget
based defaults, but I'm leaving that until we need it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106570

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/test/CodeGen/RISCV/align.ll


Index: llvm/test/CodeGen/RISCV/align.ll
===================================================================
--- llvm/test/CodeGen/RISCV/align.ll
+++ llvm/test/CodeGen/RISCV/align.ll
@@ -2,12 +2,41 @@
 ; RUN:   | FileCheck %s -check-prefix=RV32I
 ; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs < %s \
 ; RUN:   | FileCheck %s -check-prefix=RV32C
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
+; RUN:   -riscv-experimental-pref-function-alignment=3 | FileCheck %s \
+; RUN:   -check-prefix=ALIGN3
+; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs < %s \
+; RUN:   -riscv-experimental-pref-function-alignment=3 | FileCheck %s \
+; RUN:   -check-prefix=ALIGN3
+; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
+; RUN:   -riscv-experimental-pref-loop-alignment=3 | FileCheck %s \
+; RUN:   -check-prefix=LOOPALIGN
 
 define void @foo() {
 ;RV32I: .p2align 2
 ;RV32I: foo:
 ;RV32C: .p2align 1
 ;RV32C: foo:
+;ALIGN3: .p2align 3
+;ALIGN3: foo:
 entry:
   ret void
 }
+
+define void @bar(i32 %n) {
+;LOOPALIGN-LABEL: bar:
+;LOOPALIGN: .p2align        3
+;LOOPALIGN-NEXT: .LBB1_1:
+entry:
+  br label %loop
+
+loop:
+  %loop.iv = phi i32 [0, %entry], [%loop.iv.next, %loop]
+  call void @foo()
+  %loop.iv.next = add i32 %loop.iv, 1
+  %loop.cond = icmp ne i32 %loop.iv.next, %n
+  br i1 %loop.cond, label %loop, label %exit
+
+exit:
+  ret void
+}
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -42,6 +42,22 @@
 
 STATISTIC(NumTailCalls, "Number of tail calls");
 
+static cl::opt<int> ExperimentalPrefLoopAlignment(
+    "riscv-experimental-pref-loop-alignment", cl::init(0),
+    cl::desc(
+        "Sets the preferable loop alignment for experiments (as log2 bytes)"
+        "(the last riscv-experimental-pref-loop-alignment bits"
+        " of the loop header PC will be 0)."),
+    cl::Hidden);
+
+static cl::opt<int> ExperimentalPrefFunctionAlignment(
+    "riscv-experimental-pref-function-alignment", cl::init(0),
+    cl::desc(
+        "Sets the preferable function alignment for experiments (as log2 bytes)"
+        "(the last riscv-experimental-pref-loop-alignment bits"
+        " of the loop header PC will be 0)."),
+    cl::Hidden);
+
 RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
                                          const RISCVSubtarget &STI)
     : TargetLowering(TM), Subtarget(STI) {
@@ -835,7 +851,9 @@
   // Function alignments.
   const Align FunctionAlignment(Subtarget.hasStdExtC() ? 2 : 4);
   setMinFunctionAlignment(FunctionAlignment);
-  setPrefFunctionAlignment(FunctionAlignment);
+  setPrefFunctionAlignment(std::max(
+      FunctionAlignment, Align(1 << ExperimentalPrefFunctionAlignment)));
+  setPrefLoopAlignment(Align(1 << ExperimentalPrefLoopAlignment));
 
   setMinimumJumpTableEntries(5);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106570.360859.patch
Type: text/x-patch
Size: 2967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210722/01321239/attachment.bin>


More information about the llvm-commits mailing list