[llvm] [LLVM] Add `Type::getTruncatedType()` and use it in Intrinsics.cpp (PR #196239)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 11:00:44 PDT 2026


================
@@ -67,7 +67,15 @@ class IntegerType : public Type {
 
   /// Returns type twice as wide the input type.
   IntegerType *getExtendedType() const {
-    return Type::getIntNTy(getContext(), 2 * getScalarSizeInBits());
+    return Type::getIntNTy(getContext(), 2 * getBitWidth());
+  }
+
+  /// Returns type half as wide the input type.
+  IntegerType *getTruncatedType() const {
----------------
jurahul wrote:

This one is the one in integer type, so there is no mention of vector cases. The one in base Type.h has:

```
  /// Given scalar/vector integer type, returns a type with elements twice as
  /// wide as in the original type. For vectors, preserves element count.
  LLVM_ABI inline Type *getExtendedType() const;
```

For the naming, I agree that extended is too generic a name. If you have suggestion for a more specific name, we can consider it (in another PR perhaps)? We do have:

```
  /// Given an integer or vector type, change the lane bitwidth to NewBitwidth,
  /// whilst keeping the old number of lanes.
  LLVM_ABI inline Type *getWithNewBitWidth(unsigned NewBitWidth) const;
```

Maybe we can have `getWithHalfBitWidth()` and `getWithTwiceBitWidth()` (avoiding `getWithDouble` to prevent confusion with double type)? @nikic @s-barannikov WDTY? 

https://github.com/llvm/llvm-project/pull/196239


More information about the llvm-commits mailing list