Skip to content

Commit

Permalink
[RISCV] Make PostRAScheduler a target feature (#68692)
Browse files Browse the repository at this point in the history
This is what AArch64 has done in https://reviews.llvm.org/D20762.

Tests are added in macro fusion tests, which uncover a bug that
DAG mutations don't take effect.
  • Loading branch information
wangpc-pp committed Oct 11, 2023
1 parent 15d78ce commit f3c92a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Expand Up @@ -902,6 +902,9 @@ def FeatureUnalignedVectorMem
"true", "Has reasonably performant unaligned vector "
"loads and stores">;

def FeaturePostRAScheduler : SubtargetFeature<"use-postra-scheduler",
"UsePostRAScheduler", "true", "Schedule again after register allocation">;

def TuneNoOptimizedZeroStrideLoad
: SubtargetFeature<"no-optimized-zero-stride-load", "HasOptimizedZeroStrideLoad",
"false", "Hasn't optimized (perform fewer memory operations)"
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/RISCVSubtarget.h
Expand Up @@ -107,6 +107,10 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
}
bool enableMachineScheduler() const override { return true; }

bool enablePostRAScheduler() const override {
return getSchedModel().PostRAScheduler || UsePostRAScheduler;
}

Align getPrefFunctionAlignment() const {
return Align(TuneInfo->PrefFunctionAlignment);
}
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/CodeGen/RISCV/macro-fusion-lui-addi.ll
Expand Up @@ -3,6 +3,8 @@
;RUN: | FileCheck %s --check-prefix=NOFUSION
;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

@.str = private constant [4 x i8] c"%f\0A\00", align 1

Expand All @@ -20,6 +22,13 @@ define void @foo(i32 signext %0, i32 signext %1) {
; FUSION-NEXT: lui a0, %hi(.L.str)
; FUSION-NEXT: addi a0, a0, %lo(.L.str)
; FUSION-NEXT: tail bar@plt
;
; FUSION-POSTRA-LABEL: foo:
; FUSION-POSTRA: # %bb.0:
; FUSION-POSTRA-NEXT: lui a0, %hi(.L.str)
; FUSION-POSTRA-NEXT: fcvt.s.w fa0, a1
; FUSION-POSTRA-NEXT: addi a0, a0, %lo(.L.str)
; FUSION-POSTRA-NEXT: tail bar@plt
%3 = sitofp i32 %1 to float
tail call void @bar(ptr @.str, float %3)
ret void
Expand All @@ -40,5 +49,11 @@ define i32 @test_matint() {
; FUSION-NEXT: lui a0, 1
; FUSION-NEXT: addiw a0, a0, -2048
; FUSION-NEXT: ret
;
; FUSION-POSTRA-LABEL: test_matint:
; FUSION-POSTRA: # %bb.0:
; FUSION-POSTRA-NEXT: lui a0, 1
; FUSION-POSTRA-NEXT: addiw a0, a0, -2048
; FUSION-POSTRA-NEXT: ret
ret i32 2048
}

0 comments on commit f3c92a0

Please sign in to comment.