Skip to content

Commit 4b8a3b2

Browse files
committed
[RISCV] Move ActiveElementsAffectResult to TSFlags. NFC
As noted in https://github.com/llvm/llvm-project/pull/100367/files#r1695442138, the RISCVMaskedPseudoInfo currently stores two things, whether or not a masked pseudo has an unmasked variant, and whether or not it's element-wise. These are separate things, so this patch splits the latter out into the pseudo's TSFlags to help make the semantics of llvm#100367 more clear. To the best of my knowledge the only non-element-wise instructions in V are: - vredsum.vs and other reductions - vcompress.vm - vms*f.m - vcpop.m and vfirst.m - viota.m In vector crypto the pseudos that operate on element groups are conservatively marked (this might be fine to relax later given since non-EGS multiple vls are reserved), as well as the SiFive extensions.
1 parent 9b14831 commit 4b8a3b2

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ enum {
123123
// 3 -> widening case
124124
TargetOverlapConstraintTypeShift = UsesVXRMShift + 1,
125125
TargetOverlapConstraintTypeMask = 3ULL << TargetOverlapConstraintTypeShift,
126+
127+
ActiveElementsAffectResultShift = TargetOverlapConstraintTypeShift + 2,
128+
ActiveElementsAffectResultMask = 1 << ActiveElementsAffectResultShift,
126129
};
127130

128131
// Helper functions to read TSFlags.
@@ -171,6 +174,12 @@ static inline bool hasRoundModeOp(uint64_t TSFlags) {
171174
/// \returns true if this instruction uses vxrm
172175
static inline bool usesVXRM(uint64_t TSFlags) { return TSFlags & UsesVXRMMask; }
173176

177+
/// \returns true if the result in each element depends on the active elements
178+
/// e.g. non-elementwise instructions like vredsum.vs/vcompress.vm/viota.m
179+
static inline bool activeElementsAffectResult(uint64_t TSFlags) {
180+
return TSFlags & ActiveElementsAffectResultMask;
181+
}
182+
174183
static inline unsigned getVLOpNum(const MCInstrDesc &Desc) {
175184
const uint64_t TSFlags = Desc.TSFlags;
176185
// This method is only called if we expect to have a VL operand, and all

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3845,7 +3845,7 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
38453845
// Some operations produce different elementwise results depending on the
38463846
// active elements, like viota.m or vredsum. This transformation is illegal
38473847
// for these if we change the active elements (i.e. mask or VL).
3848-
if (Info->ActiveElementsAffectResult) {
3848+
if (RISCVII::activeElementsAffectResult(TrueTSFlags)) {
38493849
if (Mask && !usesAllOnesMask(Mask, Glue))
38503850
return false;
38513851
if (TrueVL != VL)

llvm/lib/Target/RISCV/RISCVInstrFormats.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ class RVInstCommon<dag outs, dag ins, string opcodestr, string argstr,
223223
// 3 -> widening case
224224
bits<2> TargetOverlapConstraintType = 0;
225225
let TSFlags{22-21} = TargetOverlapConstraintType;
226+
227+
bit ActiveElementsAffectResult = 0;
228+
let TSFlags{23} = ActiveElementsAffectResult;
226229
}
227230

228231
class RVInst<dag outs, dag ins, string opcodestr, string argstr,

llvm/lib/Target/RISCV/RISCVInstrInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ struct RISCVMaskedPseudoInfo {
383383
uint16_t MaskedPseudo;
384384
uint16_t UnmaskedPseudo;
385385
uint8_t MaskOpIdx;
386-
uint8_t ActiveElementsAffectResult : 1;
387386
};
388387
#define GET_RISCVMaskedPseudosTable_DECL
389388
#include "RISCVGenSearchableTables.inc"

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,16 @@ def RISCVVIntrinsicsTable : GenericTable {
561561
// unmasked variant. For all but compares, both the masked and
562562
// unmasked variant have a passthru and policy operand. For compares,
563563
// neither has a policy op, and only the masked version has a passthru.
564-
class RISCVMaskedPseudo<bits<4> MaskIdx, bit ActiveAffectsRes=false> {
564+
class RISCVMaskedPseudo<bits<4> MaskIdx> {
565565
Pseudo MaskedPseudo = !cast<Pseudo>(NAME);
566566
Pseudo UnmaskedPseudo = !cast<Pseudo>(!subst("_MASK", "", NAME));
567567
bits<4> MaskOpIdx = MaskIdx;
568-
bit ActiveElementsAffectResult = ActiveAffectsRes;
569568
}
570569

571570
def RISCVMaskedPseudosTable : GenericTable {
572571
let FilterClass = "RISCVMaskedPseudo";
573572
let CppTypeName = "RISCVMaskedPseudoInfo";
574-
let Fields = ["MaskedPseudo", "UnmaskedPseudo", "MaskOpIdx", "ActiveElementsAffectResult"];
573+
let Fields = ["MaskedPseudo", "UnmaskedPseudo", "MaskOpIdx"];
575574
let PrimaryKey = ["MaskedPseudo"];
576575
let PrimaryKeyName = "getMaskedPseudoInfo";
577576
}
@@ -2021,7 +2020,7 @@ multiclass VPseudoVSFS_M {
20212020
defvar constraint = "@earlyclobber $rd";
20222021
foreach mti = AllMasks in {
20232022
defvar mx = mti.LMul.MX;
2024-
let VLMul = mti.LMul.value in {
2023+
let VLMul = mti.LMul.value, ActiveElementsAffectResult = true in {
20252024
def "_M_" # mti.BX : VPseudoUnaryNoMaskNoPolicy<VR, VR, constraint>,
20262025
SchedUnary<"WriteVMSFSV", "ReadVMSFSV", mx,
20272026
forceMergeOpRead=true>;
@@ -2060,12 +2059,12 @@ multiclass VPseudoVIOTA_M {
20602059
defvar constraint = "@earlyclobber $rd";
20612060
foreach m = MxList in {
20622061
defvar mx = m.MX;
2063-
let VLMul = m.value in {
2062+
let VLMul = m.value, ActiveElementsAffectResult = 1 in {
20642063
def "_" # mx : VPseudoUnaryNoMask<m.vrclass, VR, constraint>,
20652064
SchedUnary<"WriteVIotaV", "ReadVIotaV", mx,
20662065
forceMergeOpRead=true>;
20672066
def "_" # mx # "_MASK" : VPseudoUnaryMask<m.vrclass, VR, constraint>,
2068-
RISCVMaskedPseudo<MaskIdx=2, ActiveAffectsRes=true>,
2067+
RISCVMaskedPseudo<MaskIdx=2>,
20692068
SchedUnary<"WriteVIotaV", "ReadVIotaV", mx,
20702069
forceMergeOpRead=true>;
20712070
}
@@ -2076,7 +2075,7 @@ multiclass VPseudoVCPR_V {
20762075
foreach m = MxList in {
20772076
defvar mx = m.MX;
20782077
defvar sews = SchedSEWSet<mx>.val;
2079-
let VLMul = m.value in
2078+
let VLMul = m.value, ActiveElementsAffectResult = true in
20802079
foreach e = sews in {
20812080
defvar suffix = "_" # m.MX # "_E" # e;
20822081
let SEW = e in
@@ -3158,11 +3157,11 @@ multiclass VPseudoTernaryWithTailPolicy<VReg RetClass,
31583157
DAGOperand Op2Class,
31593158
LMULInfo MInfo,
31603159
int sew> {
3161-
let VLMul = MInfo.value, SEW=sew in {
3160+
let VLMul = MInfo.value, SEW=sew, ActiveElementsAffectResult = true in {
31623161
defvar mx = MInfo.MX;
31633162
def "_" # mx # "_E" # sew : VPseudoTernaryNoMaskWithPolicy<RetClass, Op1Class, Op2Class>;
31643163
def "_" # mx # "_E" # sew # "_MASK" : VPseudoTernaryMaskPolicy<RetClass, Op1Class, Op2Class>,
3165-
RISCVMaskedPseudo<MaskIdx=3, ActiveAffectsRes=true>;
3164+
RISCVMaskedPseudo<MaskIdx=3>;
31663165
}
31673166
}
31683167

@@ -3171,15 +3170,15 @@ multiclass VPseudoTernaryWithTailPolicyRoundingMode<VReg RetClass,
31713170
DAGOperand Op2Class,
31723171
LMULInfo MInfo,
31733172
int sew> {
3174-
let VLMul = MInfo.value, SEW=sew in {
3173+
let VLMul = MInfo.value, SEW=sew, ActiveElementsAffectResult = true in {
31753174
defvar mx = MInfo.MX;
31763175
def "_" # mx # "_E" # sew
31773176
: VPseudoTernaryNoMaskWithPolicyRoundingMode<RetClass, Op1Class,
31783177
Op2Class>;
31793178
def "_" # mx # "_E" # sew # "_MASK"
31803179
: VPseudoTernaryMaskPolicyRoundingMode<RetClass, Op1Class,
31813180
Op2Class>,
3182-
RISCVMaskedPseudo<MaskIdx=3, ActiveAffectsRes=true>;
3181+
RISCVMaskedPseudo<MaskIdx=3>;
31833182
}
31843183
}
31853184

@@ -6712,14 +6711,14 @@ defm PseudoVMSET : VPseudoNullaryPseudoM<"VMXNOR">;
67126711
//===----------------------------------------------------------------------===//
67136712
// 15.2. Vector mask population count vcpop
67146713
//===----------------------------------------------------------------------===//
6715-
let IsSignExtendingOpW = 1 in
6714+
let IsSignExtendingOpW = 1, ActiveElementsAffectResult = 1 in
67166715
defm PseudoVCPOP: VPseudoVPOP_M;
67176716

67186717
//===----------------------------------------------------------------------===//
67196718
// 15.3. vfirst find-first-set mask bit
67206719
//===----------------------------------------------------------------------===//
67216720

6722-
let IsSignExtendingOpW = 1 in
6721+
let IsSignExtendingOpW = 1, ActiveElementsAffectResult = 1 in
67236722
defm PseudoVFIRST: VPseudoV1ST_M;
67246723

67256724
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ multiclass VPseudoSiFiveVFNRCLIP<string Constraint = "@earlyclobber $rd"> {
407407
UsesVXRM=0>;
408408
}
409409

410+
let ActiveElementsAffectRes = true in {
411+
410412
let Predicates = [HasVendorXSfvcp] in {
411413
foreach m = MxList in {
412414
defm X : VPseudoVC_X<m, GPR>;
@@ -458,6 +460,8 @@ let Predicates = [HasVendorXSfvfnrclipxfqf] in {
458460
defm VFNRCLIP_X_F_QF : VPseudoSiFiveVFNRCLIP;
459461
}
460462

463+
} // ActiveElementsAffectResult = true
464+
461465
// SDNode
462466
def SDT_SF_VC_V_X : SDTypeProfile<1, 4, [SDTCisVec<0>,
463467
SDTCisVT<1, XLenVT>,

llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ multiclass VPseudoBinaryV_S_NoMask_Zvk<LMULInfo m> {
278278
def "_VS_" # m.MX # "_" # vs2_lmul.MX : VPseudoBinaryNoMask_Zvk<m.vrclass, vs2_lmul.vrclass>;
279279
}
280280

281+
let ActiveElementsAffectResult = true in {
282+
281283
multiclass VPseudoVGMUL {
282284
foreach m = MxListVF4 in {
283285
defvar mx = m.MX;
@@ -397,6 +399,8 @@ multiclass VPseudoVSM3ME {
397399
}
398400
}
399401

402+
} // ActiveElementsAffectResult = true
403+
400404
multiclass VPseudoVCLMUL_VV_VX {
401405
foreach m = MxList in {
402406
defvar mx = m.MX;

0 commit comments

Comments
 (0)