[llvm] [MISched] Compare right next cluster node (PR #116584)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 9 19:47:47 PST 2024


https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/116584

>From 2ade056de9ec2725a0713200f01d659ea403a31d Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Tue, 10 Dec 2024 11:10:29 +0800
Subject: [PATCH 1/2] [RISCV] Add RUNs for different postra scheduling
 direction

---
 .../CodeGen/RISCV/macro-fusion-lui-addi.ll    | 35 +++++++++++++++----
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll b/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
index c2882fd46c17da..861297ca953372 100644
--- a/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
+++ b/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
@@ -4,7 +4,14 @@
 ;RUN: llc < %s -mtriple=riscv64 -mattr=+f,+lui-addi-fusion -mcpu=sifive-u74 \
 ;RUN:   -target-abi=lp64f | FileCheck %s --check-prefix=FUSION
 ;RUN: llc < %s -mtriple=riscv64 -mattr=+f,+lui-addi-fusion,+use-postra-scheduler -mcpu=sifive-u74 \
-;RUN:   -target-abi=lp64f | FileCheck %s --check-prefixes=FUSION-POSTRA
+;RUN:   -misched-postra-direction=topdown -target-abi=lp64f \
+;RUN:   | FileCheck %s --check-prefixes=FUSION-POSTRA,FUSION-POSTRA-TOPDOWN
+;RUN: llc < %s -mtriple=riscv64 -mattr=+f,+lui-addi-fusion,+use-postra-scheduler -mcpu=sifive-u74 \
+;RUN:   -misched-postra-direction=bottomup -target-abi=lp64f \
+;RUN:   | FileCheck %s --check-prefixes=FUSION-POSTRA,FUSION-POSTRA-BOTTOMUP
+;RUN: llc < %s -mtriple=riscv64 -mattr=+f,+lui-addi-fusion,+use-postra-scheduler -mcpu=sifive-u74 \
+;RUN:   -misched-postra-direction=bidirectional -target-abi=lp64f \
+;RUN:   | FileCheck %s --check-prefixes=FUSION-POSTRA,FUSION-POSTRA-BIDIRECTIONAL
 
 @.str = private constant [4 x i8] c"%f\0A\00", align 1
 
@@ -23,12 +30,26 @@ define void @foo(i32 signext %0, i32 signext %1) {
 ; FUSION-NEXT:    fcvt.s.w fa0, a1
 ; FUSION-NEXT:    tail bar
 ;
-; FUSION-POSTRA-LABEL: foo:
-; FUSION-POSTRA:       # %bb.0:
-; FUSION-POSTRA-NEXT:    lui a0, %hi(.L.str)
-; FUSION-POSTRA-NEXT:    addi a0, a0, %lo(.L.str)
-; FUSION-POSTRA-NEXT:    fcvt.s.w fa0, a1
-; FUSION-POSTRA-NEXT:    tail bar
+; FUSION-POSTRA-TOPDOWN-LABEL: foo:
+; FUSION-POSTRA-TOPDOWN:       # %bb.0:
+; FUSION-POSTRA-TOPDOWN-NEXT:    lui a0, %hi(.L.str)
+; FUSION-POSTRA-TOPDOWN-NEXT:    addi a0, a0, %lo(.L.str)
+; FUSION-POSTRA-TOPDOWN-NEXT:    fcvt.s.w fa0, a1
+; FUSION-POSTRA-TOPDOWN-NEXT:    tail bar
+;
+; FUSION-POSTRA-BOTTOMUP-LABEL: foo:
+; FUSION-POSTRA-BOTTOMUP:       # %bb.0:
+; FUSION-POSTRA-BOTTOMUP-NEXT:    fcvt.s.w fa0, a1
+; FUSION-POSTRA-BOTTOMUP-NEXT:    lui a0, %hi(.L.str)
+; FUSION-POSTRA-BOTTOMUP-NEXT:    addi a0, a0, %lo(.L.str)
+; FUSION-POSTRA-BOTTOMUP-NEXT:    tail bar
+;
+; FUSION-POSTRA-BIDIRECTIONAL-LABEL: foo:
+; FUSION-POSTRA-BIDIRECTIONAL:       # %bb.0:
+; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    lui a0, %hi(.L.str)
+; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    fcvt.s.w fa0, a1
+; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    addi a0, a0, %lo(.L.str)
+; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    tail bar
   %3 = sitofp i32 %1 to float
   tail call void @bar(ptr @.str, float %3)
   ret void

>From 4668368d8ff66d5f165161cf284be23f2031da47 Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Mon, 18 Nov 2024 15:33:08 +0800
Subject: [PATCH 2/2] [MISched] Compare right next cluster node

We support bottom-up and bidirectonal postra scheduling now, but we
only compare successive next cluster node as if we are doing topdown
scheduling. This makes load/store clustering and macro fusions wrong.

This patch makes sure that we can get the right cluster node by the
scheduling direction.
---
 llvm/lib/CodeGen/MachineScheduler.cpp            | 9 ++++++---
 llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 7da9b3a9c27651..1722bdda99e4af 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -3958,9 +3958,12 @@ bool PostGenericScheduler::tryCandidate(SchedCandidate &Cand,
     return TryCand.Reason != NoCand;
 
   // Keep clustered nodes together.
-  if (tryGreater(TryCand.SU == DAG->getNextClusterSucc(),
-                 Cand.SU == DAG->getNextClusterSucc(),
-                 TryCand, Cand, Cluster))
+  const SUnit *CandNextClusterSU =
+      Cand.AtTop ? DAG->getNextClusterSucc() : DAG->getNextClusterPred();
+  const SUnit *TryCandNextClusterSU =
+      TryCand.AtTop ? DAG->getNextClusterSucc() : DAG->getNextClusterPred();
+  if (tryGreater(TryCand.SU == TryCandNextClusterSU,
+                 Cand.SU == CandNextClusterSU, TryCand, Cand, Cluster))
     return TryCand.Reason != NoCand;
 
   // Avoid critical resource consumption and balance the schedule.
diff --git a/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll b/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
index 861297ca953372..3f758e25c42170 100644
--- a/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
+++ b/llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
@@ -47,8 +47,8 @@ define void @foo(i32 signext %0, i32 signext %1) {
 ; FUSION-POSTRA-BIDIRECTIONAL-LABEL: foo:
 ; FUSION-POSTRA-BIDIRECTIONAL:       # %bb.0:
 ; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    lui a0, %hi(.L.str)
-; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    fcvt.s.w fa0, a1
 ; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    addi a0, a0, %lo(.L.str)
+; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    fcvt.s.w fa0, a1
 ; FUSION-POSTRA-BIDIRECTIONAL-NEXT:    tail bar
   %3 = sitofp i32 %1 to float
   tail call void @bar(ptr @.str, float %3)



More information about the llvm-commits mailing list