[llvm] ca8d02d - [RISCV] Use a switch instead of a series of if-clauses [nfc] (try 2)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 13:44:53 PDT 2023


Author: Philip Reames
Date: 2023-10-25T13:44:46-07:00
New Revision: ca8d02d78ade46fca1569741f8f8639eb54538c7

URL: https://github.com/llvm/llvm-project/commit/ca8d02d78ade46fca1569741f8f8639eb54538c7
DIFF: https://github.com/llvm/llvm-project/commit/ca8d02d78ade46fca1569741f8f8639eb54538c7.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 91d8d91cdfe85f7..9d2b2c3b3f59264 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -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))


        


More information about the llvm-commits mailing list