[Polly][CodeGen] Allow nesting of BandAttr mark without loop.

BandAttr markers are added as parents of schedule tree bands. These also
appear as markers its equivalent AST, but a band does not necessarily
corresponds to a loop in this. Iterations may be peeled or the loop
being unrolled (e.g. if it has just one iteration). In such cases it may
happend that there is not loop between a BandAttr marker and the marker
for a loop nested in the former parent band/loop.

Handle the situation by giving priority to the inner marker over the
outer.

Fixes the polly-x86_64-linux-test-suite buildbot.

GitOrigin-RevId: 5f58aae8f3dfbac9d7321546c66309381c54d194
diff --git a/lib/CodeGen/IslNodeBuilder.cpp b/lib/CodeGen/IslNodeBuilder.cpp
index 1ce407d..fd0d50a 100644
--- a/lib/CodeGen/IslNodeBuilder.cpp
+++ b/lib/CodeGen/IslNodeBuilder.cpp
@@ -428,9 +428,14 @@
   }
 
   BandAttr *ChildLoopAttr = getLoopAttr(isl::manage_copy(Id));
+  BandAttr *AncestorLoopAttr;
   if (ChildLoopAttr) {
-    assert(!Annotator.getStagingAttrEnv() &&
-           "conflicting loop attr environments");
+    // Save current LoopAttr environment to restore again when leaving this
+    // subtree. This means there was no loop between the ancestor LoopAttr and
+    // this mark, i.e. the ancestor LoopAttr did not directly mark a loop. This
+    // can happen e.g. if the AST build peeled or unrolled the loop.
+    AncestorLoopAttr = Annotator.getStagingAttrEnv();
+
     Annotator.getStagingAttrEnv() = ChildLoopAttr;
   }
 
@@ -438,8 +443,8 @@
 
   if (ChildLoopAttr) {
     assert(Annotator.getStagingAttrEnv() == ChildLoopAttr &&
-           "Nest  must not overwrite loop attr environment");
-    Annotator.getStagingAttrEnv() = nullptr;
+           "Nest must not overwrite loop attr environment");
+    Annotator.getStagingAttrEnv() = AncestorLoopAttr;
   }
 
   isl_id_free(Id);