Skip to content

Commit ca8d02d

Browse files
committed
[RISCV] Use a switch instead of a series of if-clauses [nfc] (try 2)
This way the compiler can tell us about missing cases if we add a new value to this enum. Amusingly, the first time I landed this, I had indeed forgotten a switch case, and the build bots were quite happy to remind me of such.
1 parent 716c022 commit ca8d02d

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,23 @@ inline raw_ostream &operator<<(raw_ostream &OS, const DemandedFields &DF) {
301301
/// of instructions) which use only the Used subfields and properties.
302302
static bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType,
303303
const DemandedFields &Used) {
304-
if (Used.SEW == DemandedFields::SEWEqual &&
305-
RISCVVType::getSEW(CurVType) != RISCVVType::getSEW(NewVType))
306-
return false;
307-
308-
if (Used.SEW == DemandedFields::SEWGreaterThanOrEqual &&
309-
RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType))
310-
return false;
311-
312-
if (Used.SEW == DemandedFields::SEWGreaterThanOrEqualAndLessThan64 &&
313-
(RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType) ||
314-
RISCVVType::getSEW(NewVType) >= 64))
315-
return false;
304+
switch (Used.SEW) {
305+
case DemandedFields::SEWNone:
306+
break;
307+
case DemandedFields::SEWEqual:
308+
if (RISCVVType::getSEW(CurVType) != RISCVVType::getSEW(NewVType))
309+
return false;
310+
break;
311+
case DemandedFields::SEWGreaterThanOrEqual:
312+
if (RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType))
313+
return false;
314+
break;
315+
case DemandedFields::SEWGreaterThanOrEqualAndLessThan64:
316+
if (RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType) ||
317+
RISCVVType::getSEW(NewVType) >= 64)
318+
return false;
319+
break;
320+
}
316321

317322
if (Used.LMUL &&
318323
RISCVVType::getVLMUL(CurVType) != RISCVVType::getVLMUL(NewVType))

0 commit comments

Comments
 (0)