sdesmalen created this revision.
sdesmalen added reviewers: SjoerdMeijer, Andrzej.
Herald added subscribers: cfe-commits, tschuett.
Herald added a project: clang.

This issue was introduced when reworking D75861 
<https://reviews.llvm.org/D75861>. The bug isn't
actually hit with current unit tests because the contiguous loads/stores
infer the EltType and the MemEltType from the pointer and result, rather
than using the flags. But it will be needed for other intrinsics, such as
gather/scatter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76617

Files:
  clang/include/clang/Basic/TargetBuiltins.h
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===================================================================
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -257,31 +257,31 @@
 //===----------------------------------------------------------------------===//
 
 unsigned SVEEmitter::getTypeFlags(const SVEType &T) {
-  unsigned FirstEltType = EltTypes["FirstEltType"];
+  unsigned Shift = llvm::countTrailingZeros(EltTypes["FirstEltType"]);
   if (T.isFloat()) {
     switch (T.getElementSizeInBits()) {
-    case 16: return FirstEltType + EltTypes["EltTyFloat16"];
-    case 32: return FirstEltType + EltTypes["EltTyFloat32"];
-    case 64: return FirstEltType + EltTypes["EltTyFloat64"];
+    case 16: return EltTypes["EltTyFloat16"] << Shift;
+    case 32: return EltTypes["EltTyFloat32"] << Shift;
+    case 64: return EltTypes["EltTyFloat64"] << Shift;
     default: llvm_unreachable("Unhandled float element bitwidth!");
     }
   }
 
   if (T.isPredicateVector()) {
     switch (T.getElementSizeInBits()) {
-    case 8:  return FirstEltType + EltTypes["EltTyBool8"];
-    case 16: return FirstEltType + EltTypes["EltTyBool16"];
-    case 32: return FirstEltType + EltTypes["EltTyBool32"];
-    case 64: return FirstEltType + EltTypes["EltTyBool64"];
+    case 8:  return EltTypes["EltTyBool8"] << Shift;
+    case 16: return EltTypes["EltTyBool16"] << Shift;
+    case 32: return EltTypes["EltTyBool32"] << Shift;
+    case 64: return EltTypes["EltTyBool64"] << Shift;
     default: llvm_unreachable("Unhandled predicate element bitwidth!");
     }
   }
 
   switch (T.getElementSizeInBits()) {
-  case 8:  return FirstEltType + EltTypes["EltTyInt8"];
-  case 16: return FirstEltType + EltTypes["EltTyInt16"];
-  case 32: return FirstEltType + EltTypes["EltTyInt32"];
-  case 64: return FirstEltType + EltTypes["EltTyInt64"];
+  case 8:  return EltTypes["EltTyInt8"] << Shift;
+  case 16: return EltTypes["EltTyInt16"] << Shift;
+  case 32: return EltTypes["EltTyInt32"] << Shift;
+  case 64: return EltTypes["EltTyInt64"] << Shift;
   default: llvm_unreachable("Unhandled integer element bitwidth!");
   }
 }
@@ -681,7 +681,8 @@
   int64_t Flags = 0;
   for (auto FlagRec : FlagsList)
     Flags |= FlagRec->getValueAsInt("Value");
-  Flags |= R->getValueAsInt("MemEltType") + MemEltTypes["FirstMemEltType"];
+  Flags |= R->getValueAsInt("MemEltType")
+           << llvm::countTrailingZeros(MemEltTypes["FirstMemEltType"]);
 
   // Extract type specs from string
   SmallVector<TypeSpec, 8> TypeSpecs;
Index: clang/include/clang/Basic/TargetBuiltins.h
===================================================================
--- clang/include/clang/Basic/TargetBuiltins.h
+++ clang/include/clang/Basic/TargetBuiltins.h
@@ -17,6 +17,7 @@
 
 #include <stdint.h>
 #include "clang/Basic/Builtins.h"
+#include "llvm/Support/MathExtras.h"
 #undef PPC
 
 namespace clang {
@@ -163,6 +164,8 @@
   /// Flags to identify the types for overloaded SVE builtins.
   class SVETypeFlags {
     uint64_t Flags;
+    unsigned EltTypeShift;
+    unsigned MemEltTypeShift;
 
   public:
 #define LLVM_GET_SVE_TYPEFLAGS
@@ -181,15 +184,17 @@
 #undef LLVM_GET_SVE_MEMELTTYPES
     };
 
-    SVETypeFlags(uint64_t F) : Flags(F) {}
-    SVETypeFlags(EltType ET, bool IsUnsigned) : Flags(ET) {}
+    SVETypeFlags(uint64_t F) : Flags(F), EltTypeShift(0), MemEltTypeShift(0) {
+      EltTypeShift = llvm::countTrailingZeros(EltTypeMask);
+      MemEltTypeShift = llvm::countTrailingZeros(MemEltTypeMask);
+    }
 
     EltType getEltType() const {
-      return (EltType)((Flags & EltTypeMask) - FirstEltType);
+      return (EltType)((Flags & EltTypeMask) >> EltTypeShift);
     }
 
     MemEltType getMemEltType() const {
-      return (MemEltType)((Flags & MemEltTypeMask) - FirstMemEltType);
+      return (MemEltType)((Flags & MemEltTypeMask) >> MemEltTypeShift);
     }
 
     bool isLoad() const { return Flags & IsLoad; }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to