[llvm] [RISCV] Add load/store clustering in post machine schedule (PR #111504)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 00:28:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: None (BoyaoWang430)
<details>
<summary>Changes</summary>
#<!-- -->73789 added load clustering and #<!-- -->73796 tried to add store clustering.
If post machine schedule is used, previous cluster of load/store which formed in machine schedule may break. In order to solve this, add load/sotre clustering to post machine schedule.
---
Full diff: https://github.com/llvm/llvm-project/pull/111504.diff
2 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+13)
- (added) llvm/test/CodeGen/RISCV/misched-mem-clustering.mir (+64)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 089dc6c529193d..4c8faed5a4787a 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -363,6 +363,19 @@ class RISCVPassConfig : public TargetPassConfig {
return DAG;
}
+ ScheduleDAGInstrs *
+ createPostMachineScheduler(MachineSchedContext *C) const override {
+ ScheduleDAGMI *DAG = nullptr;
+ if (EnableMISchedLoadStoreClustering) {
+ DAG = createGenericSchedPostRA(C);
+ DAG->addMutation(createLoadClusterDAGMutation(
+ DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
+ DAG->addMutation(createStoreClusterDAGMutation(
+ DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
+ }
+ return DAG;
+ }
+
void addIRPasses() override;
bool addPreISel() override;
void addCodeGenPrepare() override;
diff --git a/llvm/test/CodeGen/RISCV/misched-mem-clustering.mir b/llvm/test/CodeGen/RISCV/misched-mem-clustering.mir
new file mode 100644
index 00000000000000..4764e08969da5d
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/misched-mem-clustering.mir
@@ -0,0 +1,64 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -mattr=+use-postra-scheduler -verify-misched -enable-post-misched=true \
+# RUN: -riscv-misched-load-store-clustering=false -debug-only=machine-scheduler \
+# RUN: -start-before=machine-scheduler -stop-after=postmisched -o - 2>&1 < %s \
+# RUN: | FileCheck -check-prefix=NOCLUSTER %s
+# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -mattr=+use-postra-scheduler -verify-misched -enable-post-misched=true \
+# RUN: -debug-only=machine-scheduler \
+# RUN: -start-before=machine-scheduler -stop-after=postmisched -o - 2>&1 < %s \
+# RUN: | FileCheck -check-prefix=MEMCLUSTER %s
+
+...
+---
+name: mem_clustering_1
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $x6, $x10, $x14, $x15, $x16, $x17
+ ; NOCLUSTER-LABEL: name: mem_clustering_1
+ ; NOCLUSTER: liveins: $x6, $x10, $x14, $x15, $x16, $x17
+ ; NOCLUSTER-NEXT: {{ $}}
+ ; NOCLUSTER-NEXT: renamable $x5 = LW renamable $x15, 0 :: (load (s32))
+ ; NOCLUSTER-NEXT: SW renamable $x14, renamable $x15, 0 :: (store (s32))
+ ; NOCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x6, killed renamable $x5
+ ; NOCLUSTER-NEXT: renamable $x7 = LW renamable $x15, 8 :: (load (s32))
+ ; NOCLUSTER-NEXT: renamable $x28 = LW renamable $x15, 16 :: (load (s32))
+ ; NOCLUSTER-NEXT: renamable $x29 = LW renamable $x15, 24 :: (load (s32))
+ ; NOCLUSTER-NEXT: renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
+ ; NOCLUSTER-NEXT: SW renamable $x14, renamable $x15, 8 :: (store (s32))
+ ; NOCLUSTER-NEXT: SW renamable $x14, renamable $x15, 16 :: (store (s32))
+ ; NOCLUSTER-NEXT: SW killed renamable $x14, killed renamable $x15, 24 :: (store (s32))
+ ; NOCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
+ ; NOCLUSTER-NEXT: renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
+ ; NOCLUSTER-NEXT: PseudoRET
+ ;
+ ; MEMCLUSTER-LABEL: name: mem_clustering_1
+ ; MEMCLUSTER: liveins: $x6, $x10, $x14, $x15, $x16, $x17
+ ; MEMCLUSTER-NEXT: {{ $}}
+ ; MEMCLUSTER-NEXT: renamable $x5 = LW renamable $x15, 0 :: (load (s32))
+ ; MEMCLUSTER-NEXT: renamable $x7 = LW renamable $x15, 8 :: (load (s32))
+ ; MEMCLUSTER-NEXT: renamable $x28 = LW renamable $x15, 16 :: (load (s32))
+ ; MEMCLUSTER-NEXT: renamable $x29 = LW renamable $x15, 24 :: (load (s32))
+ ; MEMCLUSTER-NEXT: SW renamable $x14, renamable $x15, 0 :: (store (s32))
+ ; MEMCLUSTER-NEXT: SW renamable $x14, renamable $x15, 8 :: (store (s32))
+ ; MEMCLUSTER-NEXT: SW renamable $x14, renamable $x15, 16 :: (store (s32))
+ ; MEMCLUSTER-NEXT: SW killed renamable $x14, killed renamable $x15, 24 :: (store (s32))
+ ; MEMCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x6, killed renamable $x5
+ ; MEMCLUSTER-NEXT: renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
+ ; MEMCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
+ ; MEMCLUSTER-NEXT: renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
+ ; MEMCLUSTER-NEXT: PseudoRET
+ renamable $x5 = LW renamable $x15, 0 :: (load (s32))
+ renamable $x7 = LW renamable $x15, 8 :: (load (s32))
+ renamable $x28 = LW renamable $x15, 16 :: (load (s32))
+ renamable $x29 = LW renamable $x15, 24 :: (load (s32))
+ SW renamable $x14, renamable $x15, 0 :: (store (s32))
+ SW renamable $x14, renamable $x15, 8 :: (store (s32))
+ SW renamable $x14, renamable $x15, 16 :: (store (s32))
+ SW renamable $x14, renamable $x15, 24 :: (store (s32))
+ renamable $x11 = ADDW killed renamable $x6, killed renamable $x5
+ renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
+ renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
+ renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
+ PseudoRET
+...
``````````
</details>
https://github.com/llvm/llvm-project/pull/111504
More information about the llvm-commits
mailing list