[polly] [Polly] Fix assertion in addUserAssumptions for unreachable blocks (PR #227311)

Karthika Devi C via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 06:50:49 PDT 2026


https://github.com/kartcq updated https://github.com/llvm/llvm-project/pull/227311

>From db803b743b2ae6bf2c47528b86ab1a25006fe473 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <kartc at qti.qualcomm.com>
Date: Tue, 29 Sep 2026 06:09:50 -0700
Subject: [PATCH 1/2] [Polly] Fix assertion in addUserAssumptions for
 unreachable blocks

ScopBuilder::addUserAssumptions() crashes when an llvm.assume call
resides in a block that has no entry in InvalidDomainMap. This happens
when __builtin_unreachable() is converted to llvm.assume by earlier
passes, but Polly's buildDomainsWithBranchConstraints() skips the
block (e.g. due to an UnreachableInst terminator), leaving its
InvalidDomainMap entry uninitialized.
Skip such assumptions instead of asserting.

Fixes #226718
---
 polly/lib/Analysis/ScopBuilder.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index 9d48ba2f89248..63d3d56a82c46 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -1472,6 +1472,11 @@ void ScopBuilder::addUserAssumptions(
     SmallVector<isl_set *, 2> ConditionSets;
     auto *TI = InScop ? CI->getParent()->getTerminator() : nullptr;
     BasicBlock *BB = InScop ? CI->getParent() : R.getEntry();
+
+    // Skip assumptions in blocks with no computed domain (e.g. unreachable blocks).
+    if (!InvalidDomainMap.count(BB))
+      continue;
+
     auto *Dom = InScop ? isl_set_copy(scop->getDomainConditions(BB).get())
                        : isl_set_copy(scop->getContext().get());
     assert(Dom && "Cannot propagate a nullptr.");

>From e691033baaf12c4b833ebd03d204f393e000d40b Mon Sep 17 00:00:00 2001
From: Karthika Devi C <kartc at qti.qualcomm.com>
Date: Tue, 29 Sep 2026 19:20:36 +0530
Subject: [PATCH 2/2] Update Format

---
 polly/lib/Analysis/ScopBuilder.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp
index 63d3d56a82c46..6767280dc0790 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -980,7 +980,7 @@ bool ScopBuilder::buildDomainsWithBranchConstraints(
       isl::set CondSet = isl::manage(ConditionSets[u]);
       BasicBlock *SuccBB = getRegionNodeSuccessor(RN, TI, u);
 
-      // Skip blocks outside the region.
+      blocks outside the region.
       if (!scop->contains(SuccBB))
         continue;
 
@@ -1473,7 +1473,8 @@ void ScopBuilder::addUserAssumptions(
     auto *TI = InScop ? CI->getParent()->getTerminator() : nullptr;
     BasicBlock *BB = InScop ? CI->getParent() : R.getEntry();
 
-    // Skip assumptions in blocks with no computed domain (e.g. unreachable blocks).
+    // Skip assumptions in blocks with no computed domain (e.g. unreachable
+    // blocks).
     if (!InvalidDomainMap.count(BB))
       continue;
 



More information about the llvm-commits mailing list