================
@@ -2093,10 +2093,15 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
   case Type::ExtVector:
   case Type::Vector: {
     const auto *VT = cast<VectorType>(T);
-    TypeInfo EltInfo = getTypeInfo(VT->getElementType());
-    Width = VT->isPackedVectorBoolType(*this)
-                ? VT->getNumElements()
-                : EltInfo.Width * VT->getNumElements();
+    QualType Elt = VT->getElementType();
+    uint64_t EltWidth = [&]() -> uint64_t {
----------------
steffenlarsen wrote:

We definitely could, but I fear it would make the intention less clear. I 
assume you mean something along the lines of:
```c++
uint64_t EltWidth = 1;
if (Elt.getTypePtrOrNull() && Elt.getTypePtr()->isBitIntType())
  EltWidth = Elt.getTypePtr()->castAs<BitIntType>()->getNumBits();
else if (!VT->isPackedVectorBoolType(*this))
  EltWidth = getTypeInfo(Elt).Width;
```
Since the default case would now be the last branch, determined by it not being 
the other cases and not a packed bool vector, I don't think it is very readable.

Alternatively, we could make the default case the initialization:
```c++
uint64_t EltWidth = getTypeInfo(Elt).Width;
if (Elt.getTypePtrOrNull() && Elt.getTypePtr()->isBitIntType())
  EltWidth = Elt.getTypePtr()->castAs<BitIntType>()->getNumBits();
else if (VT->isPackedVectorBoolType(*this))
  EltWidth = 1;
```
Then we run the risk of the compiler not being able to find out that there is 
no side-effects from `getTypeInfo()` and having that initialization being a 
wasted operation. It should be smart enough though, so I reckon that should be 
fine.

Personally, I personally prefer the current style (using IILF), but I don't 
feel strongly one way or the other. If you prefer one of the above suggestions 
I will make the change.

https://github.com/llvm/llvm-project/pull/161796
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to