[llvm] [IR] Avoid visited set for simple isScalableTy queries (NFC) (PR #221743)

Cullen Rhodes via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 7 23:51:43 PDT 2026


https://github.com/c-rhodes updated https://github.com/llvm/llvm-project/pull/221743

>From da2a983fe049d3cd22f63fd3d1ece52aa0823a69 Mon Sep 17 00:00:00 2001
From: Cullen Rhodes <cullen.rhodes at arm.com>
Date: Sun, 3 May 2026 21:44:36 +0000
Subject: [PATCH 1/2] [IR] Avoid visited set for simple isScalableTy queries
 (NFC)

Assisted-by: codex
---
 llvm/lib/IR/Type.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 869409e6979f3..7dd536eff2cea 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -67,6 +67,18 @@ bool Type::isScalableTy(SmallPtrSetImpl<const Type *> &Visited) const {
 }
 
 bool Type::isScalableTy() const {
+  switch (getTypeID()) {
+  case ScalableVectorTyID:
+    return true;
+  case TargetExtTyID:
+    return isScalableTargetExtTy();
+  case ArrayTyID:
+  case StructTyID:
+    break;
+  default:
+    return false;
+  }
+
   SmallPtrSet<const Type *, 4> Visited;
   return isScalableTy(Visited);
 }

>From 4e52a14b3af8ff9413bbe71b5f38791751431f47 Mon Sep 17 00:00:00 2001
From: Cullen Rhodes <cullen.rhodes at arm.com>
Date: Tue, 8 Sep 2026 06:46:58 +0000
Subject: [PATCH 2/2] address comments

---
 llvm/lib/IR/Type.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 7dd536eff2cea..9694b0064093e 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -73,14 +73,13 @@ bool Type::isScalableTy() const {
   case TargetExtTyID:
     return isScalableTargetExtTy();
   case ArrayTyID:
-  case StructTyID:
-    break;
+  case StructTyID: {
+    SmallPtrSet<const Type *, 4> Visited;
+    return isScalableTy(Visited);
+  }
   default:
     return false;
   }
-
-  SmallPtrSet<const Type *, 4> Visited;
-  return isScalableTy(Visited);
 }
 
 bool Type::containsNonGlobalTargetExtType(



More information about the llvm-commits mailing list