Skip to content

Commit af9b25f

Browse files
committed
[RISCV] Optimize floating point scalar move and splat
In D158086, we limit all floating point scalar move and splat can't fuse vsetvli with different SEW, and this patch try to relax the constraint as possible by introducing new SEW demand type: SEWGreaterThanOrEqualAndLessThan64, that allow SEW fused with larger SEW, but constraint it can't fused with SEW=64. Reviewed By: rogfer01 Differential Revision: https://reviews.llvm.org/D158177
1 parent b793c7e commit af9b25f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ struct DemandedFields {
212212
bool VLZeroness = false;
213213
// What properties of SEW we need to preserve.
214214
enum : uint8_t {
215-
SEWEqual = 2, // The exact value of SEW needs to be preserved.
216-
SEWGreaterThanOrEqual = 1, // SEW can be changed as long as it's greater
215+
SEWEqual = 3, // The exact value of SEW needs to be preserved.
216+
SEWGreaterThanOrEqual = 2, // SEW can be changed as long as it's greater
217217
// than or equal to the original value.
218-
SEWNone = 0 // We don't need to preserve SEW at all.
218+
SEWGreaterThanOrEqualAndLessThan64 =
219+
1, // SEW can be changed as long as it's greater
220+
// than or equal to the original value, but must be less
221+
// than 64.
222+
SEWNone = 0 // We don't need to preserve SEW at all.
219223
} SEW = SEWNone;
220224
bool LMUL = false;
221225
bool SEWLMULRatio = false;
@@ -267,6 +271,9 @@ struct DemandedFields {
267271
case SEWGreaterThanOrEqual:
268272
OS << "SEWGreaterThanOrEqual";
269273
break;
274+
case SEWGreaterThanOrEqualAndLessThan64:
275+
OS << "SEWGreaterThanOrEqualAndLessThan64";
276+
break;
270277
case SEWNone:
271278
OS << "SEWNone";
272279
break;
@@ -302,6 +309,11 @@ static bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType,
302309
RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType))
303310
return false;
304311

312+
if (Used.SEW == DemandedFields::SEWGreaterThanOrEqualAndLessThan64 &&
313+
(RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType) ||
314+
RISCVVType::getSEW(NewVType) >= 64))
315+
return false;
316+
305317
if (Used.LMUL &&
306318
RISCVVType::getVLMUL(CurVType) != RISCVVType::getVLMUL(NewVType))
307319
return false;
@@ -391,7 +403,9 @@ DemandedFields getDemanded(const MachineInstr &MI,
391403
// tail lanes to either be the original value or -1. We are writing
392404
// unknown bits to the lanes here.
393405
if (hasUndefinedMergeOp(MI, *MRI)) {
394-
if (!isFloatScalarMoveOrScalarSplatInstr(MI) || HasVInstructionsF64)
406+
if (isFloatScalarMoveOrScalarSplatInstr(MI) && !HasVInstructionsF64)
407+
Res.SEW = DemandedFields::SEWGreaterThanOrEqualAndLessThan64;
408+
else
395409
Res.SEW = DemandedFields::SEWGreaterThanOrEqual;
396410
Res.TailPolicy = false;
397411
}
@@ -974,7 +988,9 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
974988
Used.LMUL = false;
975989
Used.SEWLMULRatio = false;
976990
Used.VLAny = false;
977-
if (!isFloatScalarMoveOrScalarSplatInstr(MI) || HasVInstructionsF64)
991+
if (isFloatScalarMoveOrScalarSplatInstr(MI) && !HasVInstructionsF64)
992+
Used.SEW = DemandedFields::SEWGreaterThanOrEqualAndLessThan64;
993+
else
978994
Used.SEW = DemandedFields::SEWGreaterThanOrEqual;
979995
Used.TailPolicy = false;
980996
}

llvm/test/CodeGen/RISCV/rvv/vsetvli-valid-elen-fp.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ define void @bar(half %y, ptr %i32p) {
4040
; CHECK-NO-FELEN64: # %bb.0: # %entry
4141
; CHECK-NO-FELEN64-NEXT: vsetivli zero, 1, e32, m1, ta, ma
4242
; CHECK-NO-FELEN64-NEXT: vle32.v v8, (a0)
43-
; CHECK-NO-FELEN64-NEXT: vsetivli zero, 1, e16, m1, ta, ma
4443
; CHECK-NO-FELEN64-NEXT: vfmv.s.f v9, fa0
4544
; CHECK-NO-FELEN64-NEXT: #APP
4645
; CHECK-NO-FELEN64-NEXT: # use v8 v9

0 commit comments

Comments
 (0)