[polly] [Polly] Fix codegen assertions to account for DefinedBehaviorContext (PR #209188)

Karthika Devi C via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 07:09:14 PDT 2026


https://github.com/kartcq created https://github.com/llvm/llvm-project/pull/209188

DeLICM may produce new read access relations whose domain is restricted to the DefinedBehaviorContext (e.g., only valid when a parameter ensures no UB). The validation in setNewAccessRelation already accounts for this, but the debug assertions in createNewAccesses and generateScalarLoads did not, causing false assertion failures during code generation.

Intersect the checked domains with getBestKnownDefinedBehaviorContext() to match the contract that DeLICM relies on.

Fixes #205732

>From c92c9e79a96fe41cc1b574dc9d1beca654573365 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <kartc at qti.qualcomm.com>
Date: Mon, 13 Jul 2026 04:53:05 -0700
Subject: [PATCH] [Polly] Fix codegen assertions to account for
 DefinedBehaviorContext

DeLICM may produce new read access relations whose domain is restricted
to the DefinedBehaviorContext (e.g., only valid when a parameter ensures
no UB). The validation in setNewAccessRelation already accounts for this,
but the debug assertions in createNewAccesses and generateScalarLoads
did not, causing false assertion failures during code generation.

Intersect the checked domains with getBestKnownDefinedBehaviorContext()
to match the contract that DeLICM relies on.

Fixes #205732
---
 polly/lib/CodeGen/BlockGenerators.cpp | 5 +++++
 polly/lib/CodeGen/IslNodeBuilder.cpp  | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index be01f24f562b2..877bb48ad650a 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -555,6 +555,11 @@ void BlockGenerator::generateScalarLoads(
 #ifndef NDEBUG
     auto StmtDom =
         Stmt.getDomain().intersect_params(Stmt.getParent()->getContext());
+    // Restrict to defined behavior context to match DeLICM's contract:
+    // new read accesses are only required to cover the defined-behavior
+    // subset of the domain.
+    StmtDom = StmtDom.intersect_params(
+        Stmt.getParent()->getBestKnownDefinedBehaviorContext());
     auto AccDom = MA->getAccessRelation().domain();
     assert(!StmtDom.is_subset(AccDom).is_false() &&
            "Scalar must be loaded in all statement instances");
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index 924f6533b0a81..5d232afdf0642 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -803,6 +803,14 @@ IslNodeBuilder::createNewAccesses(ScopStmt *Stmt,
                                      Stmt->getParent()->getContext().release());
       SchedDom = isl_set_intersect_params(
           SchedDom, Stmt->getParent()->getContext().release());
+      // Restrict to defined behavior context to match DeLICM's contract:
+      // new read accesses are only required to cover the defined-behavior
+      // subset of the domain.
+      auto *DefinedBehavior =
+          Stmt->getParent()->getBestKnownDefinedBehaviorContext().release();
+      SchedDom =
+          isl_set_intersect_params(SchedDom, isl_set_copy(DefinedBehavior));
+      Dom = isl_set_intersect_params(Dom, DefinedBehavior);
       assert(isl_set_is_subset(SchedDom, AccDom) &&
              "Access relation not defined on full schedule domain");
       assert(isl_set_is_subset(Dom, AccDom) &&



More information about the llvm-commits mailing list