Skip to content

Commit 7df4784

Browse files
lenaryHoney Goyal
authored andcommitted
[RISCV] Rename SFB Base Feature (llvm#169607)
New SFB subsets are being added with the scheduler class name as a suffix, so now is the time to go back to the base extension and add IALU to its name. This also: - Drops a hyphen from the other SFB features for mul and minmax, to more closely match their scheduling classes. - Updates the predicates on specific SFB pseudos so we get verifier errors if we introduce the pseudos when we don't have the right subtarget feature. - Updates the SFB Documentation comment to make it no longer SiFive-specific.
1 parent 0537b26 commit 7df4784

23 files changed

+90
-64
lines changed

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,23 +1850,44 @@ def TuneNoDefaultUnroll
18501850
: SubtargetFeature<"no-default-unroll", "EnableDefaultUnroll", "false",
18511851
"Disable default unroll preference.">;
18521852

1853-
// SiFive 7 is able to fuse integer ALU operations with a preceding branch
1854-
// instruction.
1855-
def TuneShortForwardBranchOpt
1856-
: SubtargetFeature<"short-forward-branch-opt", "HasShortForwardBranchOpt",
1857-
"true", "Enable short forward branch optimization">;
1858-
def HasShortForwardBranchOpt : Predicate<"Subtarget->hasShortForwardBranchOpt()">;
1859-
def NoShortForwardBranchOpt : Predicate<"!Subtarget->hasShortForwardBranchOpt()">;
1853+
// Many Microarchitectures are able to fuse a branch over a single instruction
1854+
// with the branched-over instruction. We call this fusion "short forward
1855+
// branches".
1856+
//
1857+
// We can do this for a variety of instruction groups, depending on the
1858+
// microarch. We broadly group these by their scheduler class:
1859+
// - IALU: RVI Integer instructions, plus ANDN/ORN/XNOR (Zbb/Zbkb)
1860+
// - IMinMax: Zbb MIN(U)/MAX(U)
1861+
// - IMul: MUL
1862+
//
1863+
// We make the simplifying assumption that any microarches that implement
1864+
// any "short forward branches" can do the IALU fusions, and can opt into
1865+
// the other fusions they implement.
1866+
//
1867+
// The important Pseudo used by all these instructions requires the IALU
1868+
// short forward branches.
1869+
//
1870+
// Vendor-specific short-forward-branch opts may be added under IALU, as
1871+
// the vendor-specific instructions should only be enabled for vendor
1872+
// cores.
1873+
def TuneShortForwardBranchIALU
1874+
: SubtargetFeature<"short-forward-branch-ialu", "HasShortForwardBranchIALU",
1875+
"true", "Enable short forward branch optimization for RVI base instructions">;
1876+
def HasShortForwardBranchIALU : Predicate<"Subtarget->hasShortForwardBranchIALU()">;
1877+
def NoShortForwardBranch : Predicate<"!Subtarget->hasShortForwardBranchIALU()">;
18601878

18611879
def TuneShortForwardBranchIMinMax
1862-
: SubtargetFeature<"short-forward-branch-i-minmax", "HasShortForwardBranchIMinMax",
1863-
"true", "Enable short forward branch optimization for min,max instructions in Zbb",
1864-
[TuneShortForwardBranchOpt]>;
1880+
: SubtargetFeature<"short-forward-branch-iminmax", "HasShortForwardBranchIMinMax",
1881+
"true", "Enable short forward branch optimization for MIN,MAX instructions in Zbb",
1882+
[TuneShortForwardBranchIALU]>;
1883+
def HasShortForwardBranchIMinMax : Predicate<"Subtarget->hasShortForwardBranchIMinMax()">;
18651884

18661885
def TuneShortForwardBranchIMul
1867-
: SubtargetFeature<"short-forward-branch-i-mul", "HasShortForwardBranchIMul",
1868-
"true", "Enable short forward branch optimization for mul instruction",
1869-
[TuneShortForwardBranchOpt]>;
1886+
: SubtargetFeature<"short-forward-branch-imul", "HasShortForwardBranchIMul",
1887+
"true", "Enable short forward branch optimization for MUL instruction",
1888+
[TuneShortForwardBranchIALU]>;
1889+
def HasShortForwardBranchIMul : Predicate<"Subtarget->hasShortForwardBranchIMul()">;
1890+
18701891

18711892
// Some subtargets require a S2V transfer buffer to move scalars into vectors.
18721893
// FIXME: Forming .vx/.vf/.wx/.wf can reduce register pressure.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
453453
setOperationAction(ISD::ABS, XLenVT, Legal);
454454
if (Subtarget.is64Bit())
455455
setOperationAction(ISD::ABS, MVT::i32, Custom);
456-
} else if (Subtarget.hasShortForwardBranchOpt()) {
456+
} else if (Subtarget.hasShortForwardBranchIALU()) {
457457
// We can use PseudoCCSUB to implement ABS.
458458
setOperationAction(ISD::ABS, XLenVT, Legal);
459459
} else if (Subtarget.is64Bit()) {
@@ -9509,7 +9509,7 @@ static SDValue lowerSelectToBinOp(SDNode *N, SelectionDAG &DAG,
95099509
static SDValue
95109510
foldBinOpIntoSelectIfProfitable(SDNode *BO, SelectionDAG &DAG,
95119511
const RISCVSubtarget &Subtarget) {
9512-
if (Subtarget.hasShortForwardBranchOpt())
9512+
if (Subtarget.hasShortForwardBranchIALU())
95139513
return SDValue();
95149514

95159515
unsigned SelOpNo = 0;
@@ -21013,7 +21013,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
2101321013

2101421014
// (select (x < 0), y, z) -> x >> (XLEN - 1) & (y - z) + z
2101521015
// (select (x >= 0), y, z) -> x >> (XLEN - 1) & (z - y) + y
21016-
if (!Subtarget.hasShortForwardBranchOpt() && isa<ConstantSDNode>(TrueV) &&
21016+
if (!Subtarget.hasShortForwardBranchIALU() && isa<ConstantSDNode>(TrueV) &&
2101721017
isa<ConstantSDNode>(FalseV) && isNullConstant(RHS) &&
2101821018
(CCVal == ISD::CondCode::SETLT || CCVal == ISD::CondCode::SETGE)) {
2101921019
if (CCVal == ISD::CondCode::SETGE)
@@ -25607,7 +25607,7 @@ RISCVTargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
2560725607
return SDValue(N, 0); // Lower SDIV as SDIV
2560825608

2560925609
// Only perform this transform if short forward branch opt is supported.
25610-
if (!Subtarget.hasShortForwardBranchOpt())
25610+
if (!Subtarget.hasShortForwardBranchIALU())
2561125611
return SDValue();
2561225612
EVT VT = N->getValueType(0);
2561325613
if (!(VT == MVT::i32 || (VT == MVT::i64 && Subtarget.is64Bit())))

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ bool RISCVInstrInfo::analyzeSelect(const MachineInstr &MI,
18211821
Cond.push_back(MI.getOperand(2));
18221822
Cond.push_back(MI.getOperand(3));
18231823
// We can only fold when we support short forward branch opt.
1824-
Optimizable = STI.hasShortForwardBranchOpt();
1824+
Optimizable = STI.hasShortForwardBranchIALU();
18251825
return false;
18261826
}
18271827

@@ -1831,7 +1831,7 @@ RISCVInstrInfo::optimizeSelect(MachineInstr &MI,
18311831
bool PreferFalse) const {
18321832
assert(MI.getOpcode() == RISCV::PseudoCCMOVGPR &&
18331833
"Unknown select instruction");
1834-
if (!STI.hasShortForwardBranchOpt())
1834+
if (!STI.hasShortForwardBranchIALU())
18351835
return nullptr;
18361836

18371837
MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();

llvm/lib/Target/RISCV/RISCVInstrInfoSFB.td

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
let Predicates = [HasShortForwardBranchOpt], isSelect = 1,
13+
let Predicates = [HasShortForwardBranchIALU], isSelect = 1,
1414
Constraints = "$dst = $falsev", isCommutable = 1, Size = 8 in {
1515
// This instruction moves $truev to $dst when the condition is true. It will
1616
// be expanded to control flow in RISCVExpandPseudoInsts.
@@ -28,7 +28,7 @@ def PseudoCCMOVGPR : Pseudo<(outs GPR:$dst),
2828

2929
// This should always expand to a branch+c.mv so the size is 6 or 4 if the
3030
// branch is compressible.
31-
let Predicates = [HasConditionalMoveFusion, NoShortForwardBranchOpt],
31+
let Predicates = [HasConditionalMoveFusion, NoShortForwardBranch],
3232
Constraints = "$dst = $falsev", isCommutable = 1, Size = 6 in {
3333
// This instruction moves $truev to $dst when the condition is true. It will
3434
// be expanded to control flow in RISCVExpandPseudoInsts.
@@ -108,7 +108,7 @@ class SFBShiftW_ri
108108
// is true. Returns $falsev otherwise. Selected by optimizeSelect.
109109
// TODO: Can we use DefaultOperands on the regular binop to accomplish this more
110110
// like how ARM does predication?
111-
let Predicates = [HasShortForwardBranchOpt] in {
111+
let Predicates = [HasShortForwardBranchIALU] in {
112112
def PseudoCCADD : SFBALU_rr;
113113
def PseudoCCSUB : SFBALU_rr;
114114
def PseudoCCSLL : SFBALU_rr;
@@ -117,11 +117,6 @@ def PseudoCCSRA : SFBALU_rr;
117117
def PseudoCCAND : SFBALU_rr;
118118
def PseudoCCOR : SFBALU_rr;
119119
def PseudoCCXOR : SFBALU_rr;
120-
def PseudoCCMAX : SFBALU_rr;
121-
def PseudoCCMIN : SFBALU_rr;
122-
def PseudoCCMAXU : SFBALU_rr;
123-
def PseudoCCMINU : SFBALU_rr;
124-
def PseudoCCMUL : SFBALU_rr;
125120

126121
def PseudoCCADDI : SFBALU_ri;
127122
def PseudoCCANDI : SFBALU_ri;
@@ -153,11 +148,21 @@ def PseudoCCORN : SFBALU_rr;
153148
def PseudoCCXNOR : SFBALU_rr;
154149
}
155150

156-
let Predicates = [HasShortForwardBranchOpt] in
151+
let Predicates = [HasShortForwardBranchIALU] in
157152
def : Pat<(XLenVT (abs GPR:$rs1)),
158153
(PseudoCCSUB (XLenVT GPR:$rs1), (XLenVT X0), /* COND_LT */ 2,
159154
(XLenVT GPR:$rs1), (XLenVT X0), (XLenVT GPR:$rs1))>;
160-
let Predicates = [HasShortForwardBranchOpt, IsRV64] in
155+
let Predicates = [HasShortForwardBranchIALU, IsRV64] in
161156
def : Pat<(sext_inreg (abs 33signbits_node:$rs1), i32),
162157
(PseudoCCSUBW (i64 GPR:$rs1), (i64 X0), /* COND_LT */ 2,
163158
(i64 GPR:$rs1), (i64 X0), (i64 GPR:$rs1))>;
159+
160+
let Predicates = [HasShortForwardBranchIMinMax] in {
161+
def PseudoCCMAX : SFBALU_rr;
162+
def PseudoCCMIN : SFBALU_rr;
163+
def PseudoCCMAXU : SFBALU_rr;
164+
def PseudoCCMINU : SFBALU_rr;
165+
}
166+
167+
let Predicates = [HasShortForwardBranchIMul] in
168+
def PseudoCCMUL : SFBALU_rr;

llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ defm : VPatTernaryVD4DOT_VV<"int_riscv_nds_vd4dotsu", "PseudoNDS_VD4DOTSU",
912912
// Pseudo-instructions for SFB (Short Forward Branch)
913913
//===----------------------------------------------------------------------===//
914914

915-
let Predicates = [HasShortForwardBranchOpt], hasSideEffects = 0,
915+
let Predicates = [HasShortForwardBranchIALU], hasSideEffects = 0,
916916
mayLoad = 0, mayStore = 0, Size = 8, Constraints = "$dst = $falsev" in {
917917
def PseudoCCNDS_BFOS : Pseudo<(outs GPR:$dst),
918918
(ins GPR:$lhs, GPR:$rhs, cond_code:$cc,

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ def PseudoQC_E_SH : PseudoStore<"qc.e.sh">;
13301330
def PseudoQC_E_SW : PseudoStore<"qc.e.sw">;
13311331
} // Predicates = [HasVendorXqcilo, IsRV32]
13321332

1333-
let Predicates = [HasShortForwardBranchOpt] in {
1333+
let Predicates = [HasShortForwardBranchIALU] in {
13341334
def PseudoCCQC_LI : SFBQC_LI;
13351335
def PseudoCCQC_E_LI : SFBQC_E_LI;
13361336
}
@@ -1571,7 +1571,7 @@ def: Pat<(i32 (ctlz (not (i32 GPR:$rs1)))), (QC_CLO GPR:$rs1)>;
15711571
let Predicates = [HasVendorXqciint, IsRV32] in
15721572
def : Pat<(riscv_mileaveret_glue), (QC_C_MILEAVERET)>;
15731573

1574-
let Predicates = [HasVendorXqcicm, NoShortForwardBranchOpt, IsRV32] in {
1574+
let Predicates = [HasVendorXqcicm, NoShortForwardBranch, IsRV32] in {
15751575
def : QCIMVCCPat<SETEQ, QC_MVEQ>;
15761576
def : QCIMVCCPat<SETNE, QC_MVNE>;
15771577
def : QCIMVCCPat<SETLT, QC_MVLT>;

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def ROCKET : RISCVTuneProcessorModel<"rocket",
141141
RocketModel>;
142142

143143
defvar SiFive7TuneFeatures = [TuneSiFive7, TuneNoDefaultUnroll,
144-
TuneShortForwardBranchOpt,
144+
TuneShortForwardBranchIALU,
145145
TunePostRAScheduler];
146146
def SIFIVE_7 : RISCVTuneProcessorModel<"sifive-7-series",
147147
SiFive7Model, SiFive7TuneFeatures>;
@@ -805,7 +805,7 @@ def ANDES_AX25 : RISCVProcessorModel<"andes-ax25",
805805

806806
defvar Andes45TuneFeatures = [TuneAndes45,
807807
TuneNoDefaultUnroll,
808-
TuneShortForwardBranchOpt,
808+
TuneShortForwardBranchIALU,
809809
TunePostRAScheduler];
810810

811811
def ANDES_45 : RISCVTuneProcessorModel<"andes-45-series",

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
208208
bool hasConditionalMoveFusion() const {
209209
// Do we support fusing a branch+mv or branch+c.mv as a conditional move.
210210
return (hasConditionalCompressedMoveFusion() && hasStdExtZca()) ||
211-
hasShortForwardBranchOpt();
211+
hasShortForwardBranchIALU();
212212
}
213213

214214
bool hasShlAdd(int64_t ShAmt) const {

llvm/test/Analysis/CostModel/RISCV/cmp-select.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2-
; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f,+short-forward-branch-opt -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=SFB64
2+
; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f,+short-forward-branch-ialu -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=SFB64
33
; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=RV64
44

55
define i32 @icmp-iselect(i64 %ca, i64 %cb, i32 %a, i32 %b) {

llvm/test/CodeGen/RISCV/cmov-branch-opt.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
; RUN: | FileCheck -check-prefixes=CMOV,CMOV-NOZICOND %s
66
; RUN: llc -mtriple=riscv64 -mattr=+conditional-cmv-fusion,+c,+zicond -verify-machineinstrs < %s \
77
; RUN: | FileCheck -check-prefixes=CMOV,CMOV-ZICOND %s
8-
; RUN: llc -mtriple=riscv64 -mattr=+short-forward-branch-opt -verify-machineinstrs < %s \
8+
; RUN: llc -mtriple=riscv64 -mattr=+short-forward-branch-ialu -verify-machineinstrs < %s \
99
; RUN: | FileCheck -check-prefixes=SHORT_FORWARD,SFB-NOZICOND,SFB-NOZICOND-NOC %s
10-
; RUN: llc -mtriple=riscv64 -mattr=+short-forward-branch-opt,+c -verify-machineinstrs < %s \
10+
; RUN: llc -mtriple=riscv64 -mattr=+short-forward-branch-ialu,+c -verify-machineinstrs < %s \
1111
; RUN: | FileCheck -check-prefixes=SHORT_FORWARD,SFB-NOZICOND,SFB-NOZICOND-C %s
12-
; RUN: llc -mtriple=riscv64 -mattr=+short-forward-branch-opt,+zicond -verify-machineinstrs < %s \
12+
; RUN: llc -mtriple=riscv64 -mattr=+short-forward-branch-ialu,+zicond -verify-machineinstrs < %s \
1313
; RUN: | FileCheck -check-prefixes=SHORT_FORWARD,SFB-ZICOND %s
14-
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicm,+experimental-xqcics,+experimental-xqcicli,+zca,+short-forward-branch-opt,+conditional-cmv-fusion -verify-machineinstrs < %s \
14+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicm,+experimental-xqcics,+experimental-xqcicli,+zca,+short-forward-branch-ialu,+conditional-cmv-fusion -verify-machineinstrs < %s \
1515
; RUN: | FileCheck %s --check-prefixes=RV32IXQCI
1616

1717
; The conditional move optimization in sifive-p450 requires that only a

0 commit comments

Comments
 (0)