Skip to content

Commit

Permalink
[RISCV] Use a switch instead of a series of if-clauses [nfc] (try 2)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
preames committed Oct 25, 2023
1 parent 716c022 commit ca8d02d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,23 @@ inline raw_ostream &operator<<(raw_ostream &OS, const DemandedFields &DF) {
/// of instructions) which use only the Used subfields and properties.
static bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType,
const DemandedFields &Used) {
if (Used.SEW == DemandedFields::SEWEqual &&
RISCVVType::getSEW(CurVType) != RISCVVType::getSEW(NewVType))
return false;

if (Used.SEW == DemandedFields::SEWGreaterThanOrEqual &&
RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType))
return false;

if (Used.SEW == DemandedFields::SEWGreaterThanOrEqualAndLessThan64 &&
(RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType) ||
RISCVVType::getSEW(NewVType) >= 64))
return false;
switch (Used.SEW) {
case DemandedFields::SEWNone:
break;
case DemandedFields::SEWEqual:
if (RISCVVType::getSEW(CurVType) != RISCVVType::getSEW(NewVType))
return false;
break;
case DemandedFields::SEWGreaterThanOrEqual:
if (RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType))
return false;
break;
case DemandedFields::SEWGreaterThanOrEqualAndLessThan64:
if (RISCVVType::getSEW(NewVType) < RISCVVType::getSEW(CurVType) ||
RISCVVType::getSEW(NewVType) >= 64)
return false;
break;
}

if (Used.LMUL &&
RISCVVType::getVLMUL(CurVType) != RISCVVType::getVLMUL(NewVType))
Expand Down

0 comments on commit ca8d02d

Please sign in to comment.