Index: polly/unittests/Isl/IslTest.cpp
===================================================================
--- polly/unittests/Isl/IslTest.cpp
+++ polly/unittests/Isl/IslTest.cpp
@@ -644,16 +644,16 @@
                                                         &isl_ctx_free);
 
   // Basic usage
-  EXPECT_EQ(0, getNumScatterDims(UMAP("{ [] -> [] }")));
-  EXPECT_EQ(1, getNumScatterDims(UMAP("{ [] -> [i] }")));
-  EXPECT_EQ(2, getNumScatterDims(UMAP("{ [] -> [i,j] }")));
-  EXPECT_EQ(3, getNumScatterDims(UMAP("{ [] -> [i,j,k] }")));
+  EXPECT_EQ(0u, getNumScatterDims(UMAP("{ [] -> [] }")));
+  EXPECT_EQ(1u, getNumScatterDims(UMAP("{ [] -> [i] }")));
+  EXPECT_EQ(2u, getNumScatterDims(UMAP("{ [] -> [i,j] }")));
+  EXPECT_EQ(3u, getNumScatterDims(UMAP("{ [] -> [i,j,k] }")));
 
   // Different scatter spaces
-  EXPECT_EQ(0, getNumScatterDims(UMAP("{ A[] -> []; [] -> []}")));
-  EXPECT_EQ(1, getNumScatterDims(UMAP("{ A[] -> []; [] -> [i] }")));
-  EXPECT_EQ(2, getNumScatterDims(UMAP("{ A[] -> [i]; [] -> [i,j] }")));
-  EXPECT_EQ(3, getNumScatterDims(UMAP("{ A[] -> [i]; [] -> [i,j,k] }")));
+  EXPECT_EQ(0u, getNumScatterDims(UMAP("{ A[] -> []; [] -> []}")));
+  EXPECT_EQ(1u, getNumScatterDims(UMAP("{ A[] -> []; [] -> [i] }")));
+  EXPECT_EQ(2u, getNumScatterDims(UMAP("{ A[] -> [i]; [] -> [i,j] }")));
+  EXPECT_EQ(3u, getNumScatterDims(UMAP("{ A[] -> [i]; [] -> [i,j,k] }")));
 }
 
 TEST(ISLTools, getScatterSpace) {
Index: polly/lib/Transform/ZoneAlgo.cpp
===================================================================
--- polly/lib/Transform/ZoneAlgo.cpp
+++ polly/lib/Transform/ZoneAlgo.cpp
@@ -686,12 +686,11 @@
                    TargetStmt->getSurroundingLoop())) {
     isl::set DefDomain = getDomainFor(DefStmt);
     isl::set TargetDomain = getDomainFor(TargetStmt);
-    assert(DefDomain.tuple_dim().release() <=
-           TargetDomain.tuple_dim().release());
+    assert(unsignedFromIslSize(DefDomain.tuple_dim()) <=
+           unsignedFromIslSize(TargetDomain.tuple_dim()));
 
     Result = isl::map::from_domain_and_range(DefDomain, TargetDomain);
-    for (unsigned i = 0, DefDims = DefDomain.tuple_dim().release(); i < DefDims;
-         i += 1)
+    for (unsigned i : rangeIslSize(0, DefDomain.tuple_dim()))
       Result = Result.equate(isl::dim::in, i, isl::dim::out, i);
   }
 
Index: polly/lib/Transform/Simplify.cpp
===================================================================
--- polly/lib/Transform/Simplify.cpp
+++ polly/lib/Transform/Simplify.cpp
@@ -37,7 +37,7 @@
 /// that the analysis of accesses in a statement is becoming too complex. Chosen
 /// to be relatively small because all the common cases should access only few
 /// array elements per statement.
-static int const SimplifyMaxDisjuncts = 4;
+static unsigned const SimplifyMaxDisjuncts = 4;
 
 TWO_STATISTICS(ScopsProcessed, "Number of SCoPs processed");
 TWO_STATISTICS(ScopsModified, "Number of SCoPs simplified");
@@ -95,18 +95,19 @@
 
   // Fast path: If known that we cannot exceed the disjunct limit, just add
   // them.
-  if (isl_map_n_basic_map(PrevMap.get()) + isl_map_n_basic_map(Map.get()) <=
+  if (unsignedFromIslSize(PrevMap.n_basic_map()) +
+          unsignedFromIslSize(Map.n_basic_map()) <=
       SimplifyMaxDisjuncts)
     return UMap.unite(Map);
 
   isl::map Result = isl::map::empty(PrevMap.get_space());
   for (isl::basic_map BMap : PrevMap.get_basic_map_list()) {
-    if (Result.n_basic_map().release() > SimplifyMaxDisjuncts)
+    if (unsignedFromIslSize(Result.n_basic_map()) > SimplifyMaxDisjuncts)
       break;
     Result = Result.unite(BMap);
   }
   for (isl::basic_map BMap : Map.get_basic_map_list()) {
-    if (isl_map_n_basic_map(Result.get()) > SimplifyMaxDisjuncts)
+    if (unsignedFromIslSize(Result.n_basic_map()) > SimplifyMaxDisjuncts)
       break;
     Result = Result.unite(BMap);
   }
Index: polly/lib/Transform/ScheduleTreeTransform.cpp
===================================================================
--- polly/lib/Transform/ScheduleTreeTransform.cpp
+++ polly/lib/Transform/ScheduleTreeTransform.cpp
@@ -58,7 +58,7 @@
 template <typename CbTy>
 static isl::schedule rebuildBand(isl::schedule_node_band OldBand,
                                  isl::schedule Body, CbTy IncludeCb) {
-  int NumBandDims = OldBand.n_member().release();
+  int NumBandDims = unsignedFromIslSize(OldBand.n_member());
 
   bool ExcludeAny = false;
   bool IncludeAny = false;
@@ -323,7 +323,7 @@
     isl::union_map NewPartialSchedMap = isl::union_map::from(PartialSched);
     unsigned BandDims = isl_schedule_node_band_n_member(OldNode.get());
     for (isl::map Ext : NewChildExtensions.get_map_list()) {
-      unsigned ExtDims = Ext.domain_tuple_dim().release();
+      unsigned ExtDims = unsignedFromIslSize(Ext.domain_tuple_dim());
       assert(ExtDims >= BandDims);
       unsigned OuterDims = ExtDims - BandDims;
 
@@ -574,7 +574,8 @@
 /// @param Set         A set, which should be modified.
 /// @param VectorWidth A parameter, which determines the constraint.
 static isl::set addExtentConstraints(isl::set Set, int VectorWidth) {
-  unsigned Dims = Set.tuple_dim().release();
+  unsigned Dims = unsignedFromIslSize(Set.tuple_dim());
+  assert(Dims >= 1);
   isl::space Space = Set.get_space();
   isl::local_space LocalSpace = isl::local_space(Space);
   isl::constraint ExtConstr = isl::constraint::alloc_inequality(LocalSpace);
@@ -602,7 +603,7 @@
     // Do not merge permutable band to avoid loosing the permutability property.
     // Cannot collapse even two permutable loops, they might be permutable
     // individually, but not necassarily accross.
-    if (Band.n_member().release() > 1 && Band.permutable())
+    if (unsignedFromIslSize(Band.n_member()) > 1u && Band.permutable())
       return getBase().visitBand(Band);
 
     // Find collapsable bands.
@@ -611,7 +612,7 @@
     isl::schedule_node Body;
     while (true) {
       Nest.push_back(Band);
-      NumTotalLoops += Band.n_member().release();
+      NumTotalLoops += unsignedFromIslSize(Band.n_member());
       Body = Band.first_child();
       if (!Body.isa<isl::schedule_node_band>())
         break;
@@ -619,7 +620,7 @@
 
       // Do not include next band if it is permutable to not lose its
       // permutability property.
-      if (Band.n_member().release() > 1 && Band.permutable())
+      if (unsignedFromIslSize(Band.n_member()) > 1u && Band.permutable())
         break;
     }
 
@@ -640,7 +641,7 @@
     // Collect partial schedules from all members.
     isl::union_pw_aff_list PartScheds{Ctx, NumTotalLoops};
     for (isl::schedule_node_band Band : Nest) {
-      int NumLoops = Band.n_member().release();
+      int NumLoops = unsignedFromIslSize(Band.n_member());
       isl::multi_union_pw_aff BandScheds = Band.get_partial_schedule();
       for (auto j : seq<int>(0, NumLoops))
         PartScheds = PartScheds.add(BandScheds.at(j));
@@ -657,7 +658,7 @@
     // Copy over loop attributes form original bands.
     int LoopIdx = 0;
     for (isl::schedule_node_band Band : Nest) {
-      int NumLoops = Band.n_member().release();
+      int NumLoops = unsignedFromIslSize(Band.n_member());
       for (int i : seq<int>(0, NumLoops)) {
         CollapsedBand = applyBandMemberAttributes(std::move(CollapsedBand),
                                                   LoopIdx, Band, i);
@@ -713,7 +714,7 @@
 /// everything that we already know is executed in-order.
 static isl::union_map remainingDepsFromPartialSchedule(isl::union_map PartSched,
                                                        isl::union_map Deps) {
-  int NumDims = getNumScatterDims(PartSched);
+  unsigned NumDims = getNumScatterDims(PartSched);
   auto ParamSpace = PartSched.get_space().params();
 
   // { Scatter[] }
@@ -876,7 +877,8 @@
     // { Domain[] -> Scatter[] }
     isl::union_map PartSched =
         isl::union_map::from(Band.get_partial_schedule());
-    assert(getNumScatterDims(PartSched) == Band.n_member().release());
+    assert(getNumScatterDims(PartSched) ==
+           unsignedFromIslSize(Band.n_member()));
     isl::space ParamSpace = PartSched.get_space().params();
 
     // { Scatter[] -> Domain[] }
@@ -1030,7 +1032,7 @@
 
   isl::multi_union_pw_aff PartialSched = isl::manage(
       isl_schedule_node_band_get_partial_schedule(BandToUnroll.get()));
-  assert(PartialSched.dim(isl::dim::out).release() == 1 &&
+  assert(unsignedFromIslSize(PartialSched.dim(isl::dim::out)) == 1u &&
          "Can only unroll a single dimension");
   isl::union_pw_aff PartialSchedUAff = PartialSched.at(0);
 
@@ -1139,7 +1141,8 @@
 
 isl::set polly::getPartialTilePrefixes(isl::set ScheduleRange,
                                        int VectorWidth) {
-  isl_size Dims = ScheduleRange.tuple_dim().release();
+  unsigned Dims = unsignedFromIslSize(ScheduleRange.tuple_dim());
+  assert(Dims >= 1);
   isl::set LoopPrefixes =
       ScheduleRange.drop_constraints_involving_dims(isl::dim::set, Dims - 1, 1);
   auto ExtentPrefixes = addExtentConstraints(LoopPrefixes, VectorWidth);
@@ -1150,8 +1153,8 @@
 }
 
 isl::union_set polly::getIsolateOptions(isl::set IsolateDomain,
-                                        isl_size OutDimsNum) {
-  isl_size Dims = IsolateDomain.tuple_dim().release();
+                                        unsigned OutDimsNum) {
+  unsigned Dims = unsignedFromIslSize(IsolateDomain.tuple_dim());
   assert(OutDimsNum <= Dims &&
          "The isl::set IsolateDomain is used to describe the range of schedule "
          "dimensions values, which should be isolated. Consequently, the "
@@ -1182,9 +1185,8 @@
   auto Dims = Space.dim(isl::dim::set);
   auto Sizes = isl::multi_val::zero(Space);
   std::string IdentifierString(Identifier);
-  for (auto i : seq<isl_size>(0, Dims.release())) {
-    auto tileSize =
-        i < (isl_size)TileSizes.size() ? TileSizes[i] : DefaultTileSize;
+  for (auto i : rangeIslSize(0, Dims)) {
+    auto tileSize = i < TileSizes.size() ? TileSizes[i] : DefaultTileSize;
     Sizes = Sizes.set_val(i, isl::val(Node.ctx(), tileSize));
   }
   auto TileLoopMarkerStr = IdentifierString + " - Tiles";
Index: polly/lib/Transform/ScheduleOptimizer.cpp
===================================================================
--- polly/lib/Transform/ScheduleOptimizer.cpp
+++ polly/lib/Transform/ScheduleOptimizer.cpp
@@ -53,6 +53,7 @@
 #include "polly/Options.h"
 #include "polly/ScheduleTreeTransform.h"
 #include "polly/Support/ISLOStream.h"
+#include "polly/Support/ISLTools.h"
 #include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
@@ -388,15 +389,15 @@
   assert(isl_schedule_node_get_type(Node.get()) == isl_schedule_node_band);
 
   auto Space = isl::manage(isl_schedule_node_band_get_space(Node.get()));
-  isl_size ScheduleDimensions = Space.dim(isl::dim::set).release();
-  assert((isl_size)DimToVectorize < ScheduleDimensions);
+  unsigned ScheduleDimensions = unsignedFromIslSize(Space.dim(isl::dim::set));
+  assert(DimToVectorize < ScheduleDimensions);
 
   if (DimToVectorize > 0) {
     Node = isl::manage(
         isl_schedule_node_band_split(Node.release(), DimToVectorize));
     Node = Node.child(0);
   }
-  if ((isl_size)DimToVectorize < ScheduleDimensions - 1)
+  if (DimToVectorize < ScheduleDimensions - 1)
     Node = isl::manage(isl_schedule_node_band_split(Node.release(), 1));
   Space = isl::manage(isl_schedule_node_band_get_space(Node.get()));
   auto Sizes = isl::multi_val::zero(Space);
@@ -456,9 +457,8 @@
     return false;
 
   auto Space = isl::manage(isl_schedule_node_band_get_space(Node.get()));
-  auto Dims = Space.dim(isl::dim::set).release();
 
-  if (Dims <= 1)
+  if (unsignedFromIslSize(Space.dim(isl::dim::set)) <= 1u)
     return false;
 
   return isSimpleInnermostBand(Node);
@@ -490,7 +490,7 @@
 isl::schedule_node
 ScheduleTreeOptimizer::applyPrevectBandOpt(isl::schedule_node Node) {
   auto Space = isl::manage(isl_schedule_node_band_get_space(Node.get()));
-  auto Dims = Space.dim(isl::dim::set).release();
+  int Dims = unsignedFromIslSize(Space.dim(isl::dim::set));
 
   for (int i = Dims - 1; i >= 0; i--)
     if (Node.as<isl::schedule_node_band>().member_get_coincident(i)) {
Index: polly/lib/Transform/MaximalStaticExpansion.cpp
===================================================================
--- polly/lib/Transform/MaximalStaticExpansion.cpp
+++ polly/lib/Transform/MaximalStaticExpansion.cpp
@@ -118,10 +118,11 @@
 /// i.e. there are two constants Min and Max, such that every value x of the
 /// chosen dimensions is Min <= x <= Max.
 static bool isDimBoundedByConstant(isl::set Set, unsigned dim) {
-  auto ParamDims = Set.dim(isl::dim::param).release();
+  auto ParamDims = unsignedFromIslSize(Set.dim(isl::dim::param));
   Set = Set.project_out(isl::dim::param, 0, ParamDims);
   Set = Set.project_out(isl::dim::set, 0, dim);
-  auto SetDims = Set.tuple_dim().release();
+  auto SetDims = unsignedFromIslSize(Set.tuple_dim());
+  assert(SetDims >= 1);
   Set = Set.project_out(isl::dim::set, 1, SetDims - 1);
   return bool(Set.is_bounded());
 }
@@ -350,7 +351,8 @@
   // Get the current AM.
   auto CurrentAccessMap = MA->getAccessRelation();
 
-  unsigned in_dimensions = CurrentAccessMap.domain_tuple_dim().release();
+  unsigned in_dimensions =
+      unsignedFromIslSize(CurrentAccessMap.domain_tuple_dim());
 
   // Get domain from the current AM.
   auto Domain = CurrentAccessMap.domain();
@@ -404,8 +406,8 @@
 
   // Add constraints to linked output with input id.
   auto SpaceMap = NewAccessMap.get_space();
-  auto ConstraintBasicMap =
-      isl::basic_map::equal(SpaceMap, SpaceMap.dim(isl::dim::in).release());
+  auto ConstraintBasicMap = isl::basic_map::equal(
+      SpaceMap, unsignedFromIslSize(SpaceMap.dim(isl::dim::in)));
   NewAccessMap = isl::map(ConstraintBasicMap);
 
   // Set the new access relation map.
Index: polly/lib/Transform/MatmulOptimizer.cpp
===================================================================
--- polly/lib/Transform/MatmulOptimizer.cpp
+++ polly/lib/Transform/MatmulOptimizer.cpp
@@ -188,8 +188,8 @@
 /// @return        The modified map.
 static isl::map permuteDimensions(isl::map Map, isl::dim DimType,
                                   unsigned DstPos, unsigned SrcPos) {
-  assert((isl_size)DstPos < Map.dim(DimType).release() &&
-         (isl_size)SrcPos < Map.dim(DimType).release());
+  assert(DstPos < unsignedFromIslSize(Map.dim(DimType)) &&
+         SrcPos < unsignedFromIslSize(Map.dim(DimType)));
   if (DstPos == SrcPos)
     return Map;
   isl::id DimId;
@@ -229,7 +229,7 @@
   isl::space Space = AccMap.get_space();
   isl::map Universe = isl::map::universe(Space);
 
-  if (Space.dim(isl::dim::out).release() != 2)
+  if (unsignedFromIslSize(Space.dim(isl::dim::out)) != 2)
     return false;
 
   // MatMul has the form:
@@ -317,7 +317,7 @@
                                     MatMulInfoTy &MMI) {
   auto InputDimId = PartialSchedule.get_tuple_id(isl::dim::in);
   auto *Stmt = static_cast<ScopStmt *>(InputDimId.get_user());
-  isl_size OutDimNum = PartialSchedule.range_tuple_dim().release();
+  unsigned OutDimNum = unsignedFromIslSize(PartialSchedule.range_tuple_dim());
   assert(OutDimNum > 2 && "In case of the matrix multiplication the loop nest "
                           "and, consequently, the corresponding scheduling "
                           "functions have at least three dimensions.");
@@ -363,7 +363,7 @@
   auto DomainSpace = Schedule.get_space().domain();
   auto Space = DomainSpace.map_from_domain_and_range(DomainSpace);
   auto Deltas = Dep.extract_map(Space).deltas();
-  isl_size DeltasDimNum = Deltas.dim(isl::dim::set).release();
+  int DeltasDimNum = unsignedFromIslSize(Deltas.dim(isl::dim::set));
   for (int i = 0; i < DeltasDimNum; i++) {
     auto Val = Deltas.plain_get_val_if_fixed(isl::dim::set, i);
     Pos = Pos < 0 && Val.is_one() ? i : Pos;
@@ -727,9 +727,10 @@
   ScopStmt *CopyStmt = S->addScopStmt(AccRelB, AccRelPackedB, Domain);
   MMI.B->setNewAccessRelation(AccRelPackedB);
 
+  unsigned Dim = unsignedFromIslSize(MapOldIndVar.range_tuple_dim());
+  assert(Dim >= 2);
   // Insert into the schedule tree.
-  isl::map ExtMap = MapOldIndVar.project_out(
-      isl::dim::out, 2, MapOldIndVar.range_tuple_dim().release() - 2);
+  isl::map ExtMap = MapOldIndVar.project_out(isl::dim::out, 2, Dim - 2);
   ExtMap = ExtMap.reverse();
   ExtMap = ExtMap.fix_si(isl::dim::out, MMI.i, 0);
   ExtMap = ExtMap.intersect_range(Domain);
@@ -870,9 +871,9 @@
   auto Child = Node.child(0);
   auto UnMapOldIndVar = Child.get_prefix_schedule_union_map();
   auto MapOldIndVar = isl::map::from_union_map(UnMapOldIndVar);
-  if (MapOldIndVar.range_tuple_dim().release() > 9)
-    return MapOldIndVar.project_out(
-        isl::dim::out, 0, MapOldIndVar.range_tuple_dim().release() - 9);
+  unsigned Dim = unsignedFromIslSize(MapOldIndVar.range_tuple_dim());
+  if (Dim > 9u)
+    return MapOldIndVar.project_out(isl::dim::out, 0, Dim - 9);
   return MapOldIndVar;
 }
 
@@ -896,7 +897,8 @@
   isl::schedule_node Child = Node.child(0);
   isl::union_map UnMapOldIndVar = Child.get_prefix_schedule_relation();
   isl::set Prefix = isl::map::from_union_map(UnMapOldIndVar).range();
-  isl_size Dims = Prefix.tuple_dim().release();
+  unsigned Dims = unsignedFromIslSize(Prefix.tuple_dim());
+  assert(Dims >= 1);
   Prefix = Prefix.project_out(isl::dim::set, Dims - 1, 1);
   Prefix = getPartialTilePrefixes(Prefix, MicroKernelParams.Nr);
   Prefix = getPartialTilePrefixes(Prefix, MicroKernelParams.Mr);
@@ -940,8 +942,8 @@
   auto Domain = Node.get_universe_domain();
   assert(isl_union_set_n_set(Domain.get()) == 1);
   if (Node.get_schedule_depth().release() != 0 ||
-      (isl::set(Domain).tuple_dim().release() !=
-       isl_schedule_node_band_n_member(Node.get())))
+      (unsignedFromIslSize(isl::set(Domain).tuple_dim()) !=
+       unsignedFromIslSize(Node.as<isl::schedule_node_band>().n_member())))
     return Node;
   Node = isl::manage(isl_schedule_node_delete(Node.copy()));
   auto PartialSchedulePwAff = Domain.identity_union_pw_multi_aff();
Index: polly/lib/Transform/FlattenAlgo.cpp
===================================================================
--- polly/lib/Transform/FlattenAlgo.cpp
+++ polly/lib/Transform/FlattenAlgo.cpp
@@ -26,10 +26,11 @@
 /// i.e. there are two constants Min and Max, such that every value x of the
 /// chosen dimensions is Min <= x <= Max.
 bool isDimBoundedByConstant(isl::set Set, unsigned dim) {
-  auto ParamDims = Set.dim(isl::dim::param).release();
+  auto ParamDims = unsignedFromIslSize(Set.dim(isl::dim::param));
   Set = Set.project_out(isl::dim::param, 0, ParamDims);
   Set = Set.project_out(isl::dim::set, 0, dim);
-  auto SetDims = Set.tuple_dim().release();
+  auto SetDims = unsignedFromIslSize(Set.tuple_dim());
+  assert(SetDims >= 1);
   Set = Set.project_out(isl::dim::set, 1, SetDims - 1);
   return bool(Set.is_bounded());
 }
@@ -40,7 +41,8 @@
 /// Min_p <= x <= Max_p.
 bool isDimBoundedByParameter(isl::set Set, unsigned dim) {
   Set = Set.project_out(isl::dim::set, 0, dim);
-  auto SetDims = Set.tuple_dim().release();
+  auto SetDims = unsignedFromIslSize(Set.tuple_dim());
+  assert(SetDims >= 1);
   Set = Set.project_out(isl::dim::set, 1, SetDims - 1);
   return bool(Set.is_bounded());
 }
@@ -124,27 +126,12 @@
   return Result;
 }
 
-/// Return the number of dimensions in the input map's range.
-///
-/// Because this function takes an isl_union_map, the out dimensions could be
-/// different. We return the maximum number in this case. However, a different
-/// number of dimensions is not supported by the other code in this file.
-isl_size scheduleScatterDims(const isl::union_map &Schedule) {
-  isl_size Dims = 0;
-  for (isl::map Map : Schedule.get_map_list()) {
-    if (Map.is_null())
-      continue;
-
-    Dims = std::max(Dims, Map.range_tuple_dim().release());
-  }
-  return Dims;
-}
-
 /// Return the @p pos' range dimension, converted to an isl_union_pw_aff.
 isl::union_pw_aff scheduleExtractDimAff(isl::union_map UMap, unsigned pos) {
   auto SingleUMap = isl::union_map::empty(UMap.ctx());
   for (isl::map Map : UMap.get_map_list()) {
-    unsigned MapDims = Map.range_tuple_dim().release();
+    unsigned MapDims = unsignedFromIslSize(Map.range_tuple_dim());
+    assert(MapDims > pos);
     isl::map SingleMap = Map.project_out(isl::dim::out, 0, pos);
     SingleMap = SingleMap.project_out(isl::dim::out, 1, MapDims - pos - 1);
     SingleUMap = SingleUMap.unite(SingleMap);
@@ -179,8 +166,8 @@
   auto ScatterSet = isl::set(Schedule.range());
 
   auto ParamSpace = Schedule.get_space().params();
-  auto Dims = ScatterSet.tuple_dim().release();
-  assert(Dims >= 2);
+  auto Dims = unsignedFromIslSize(ScatterSet.tuple_dim());
+  assert(Dims >= 2u);
 
   // Would cause an infinite loop.
   if (!isDimBoundedByConstant(ScatterSet, 0)) {
@@ -205,7 +192,8 @@
     SubSchedule = scheduleProjectOut(SubSchedule, 0, 1);
     SubSchedule = flattenSchedule(SubSchedule);
 
-    auto SubDims = scheduleScatterDims(SubSchedule);
+    unsigned SubDims = getNumScatterDims(SubSchedule);
+    assert(SubDims >= 1);
     auto FirstSubSchedule = scheduleProjectOut(SubSchedule, 1, SubDims - 1);
     auto FirstScheduleAff = scheduleExtractDimAff(FirstSubSchedule, 0);
     auto RemainingSubSchedule = scheduleProjectOut(SubSchedule, 0, 1);
@@ -264,14 +252,16 @@
 /// largest value. Then, construct a new schedule
 ///   { Stmt[i] -> [i * (u_X() - l_X() + 1), ...] }
 isl::union_map tryFlattenLoop(isl::union_map Schedule) {
-  assert(scheduleScatterDims(Schedule) >= 2);
+  assert(getNumScatterDims(Schedule) >= 2);
 
   auto Remaining = scheduleProjectOut(Schedule, 0, 1);
   auto SubSchedule = flattenSchedule(Remaining);
-  auto SubDims = scheduleScatterDims(SubSchedule);
+  unsigned SubDims = getNumScatterDims(SubSchedule);
+
+  assert(SubDims >= 1);
 
   auto SubExtent = isl::set(SubSchedule.range());
-  auto SubExtentDims = SubExtent.dim(isl::dim::param).release();
+  auto SubExtentDims = unsignedFromIslSize(SubExtent.dim(isl::dim::param));
   SubExtent = SubExtent.project_out(isl::dim::param, 0, SubExtentDims);
   SubExtent = SubExtent.project_out(isl::dim::set, 1, SubDims - 1);
 
@@ -313,7 +303,7 @@
 } // anonymous namespace
 
 isl::union_map polly::flattenSchedule(isl::union_map Schedule) {
-  auto Dims = scheduleScatterDims(Schedule);
+  unsigned Dims = getNumScatterDims(Schedule);
   LLVM_DEBUG(dbgs() << "Recursive schedule to process:\n  " << Schedule
                     << "\n");
 
Index: polly/lib/Support/ISLTools.cpp
===================================================================
--- polly/lib/Support/ISLTools.cpp
+++ polly/lib/Support/ISLTools.cpp
@@ -56,8 +56,8 @@
   assert(FromSpace1.is_set());
   assert(FromSpace2.is_set());
 
-  unsigned Dims1 = FromSpace1.dim(isl::dim::set).release();
-  unsigned Dims2 = FromSpace2.dim(isl::dim::set).release();
+  unsigned Dims1 = unsignedFromIslSize(FromSpace1.dim(isl::dim::set));
+  unsigned Dims2 = unsignedFromIslSize(FromSpace2.dim(isl::dim::set));
 
   isl::space FromSpace =
       FromSpace1.map_from_domain_and_range(FromSpace2).wrap();
@@ -160,13 +160,13 @@
   return Result;
 }
 
-isl_size polly::getNumScatterDims(const isl::union_map &Schedule) {
-  isl_size Dims = 0;
+unsigned polly::getNumScatterDims(const isl::union_map &Schedule) {
+  unsigned Dims = 0;
   for (isl::map Map : Schedule.get_map_list()) {
     if (Map.is_null())
       continue;
 
-    Dims = std::max(Dims, Map.range_tuple_dim().release());
+    Dims = std::max(Dims, unsignedFromIslSize(Map.range_tuple_dim()));
   }
   return Dims;
 }
@@ -214,7 +214,7 @@
 }
 
 isl::set polly::shiftDim(isl::set Set, int Pos, int Amount) {
-  int NumDims = Set.tuple_dim().release();
+  unsigned NumDims = unsignedFromIslSize(Set.tuple_dim());
   if (Pos < 0)
     Pos = NumDims + Pos;
   assert(Pos < NumDims && "Dimension index must be in range");
@@ -235,7 +235,7 @@
 }
 
 isl::map polly::shiftDim(isl::map Map, isl::dim Dim, int Pos, int Amount) {
-  int NumDims = Map.dim(Dim).release();
+  unsigned NumDims = unsignedFromIslSize(Map.dim(Dim));
   if (Pos < 0)
     Pos = NumDims + Pos;
   assert(Pos < NumDims && "Dimension index must be in range");
@@ -449,16 +449,16 @@
   isl::space DomainSpace = Space.domain();
   if (DomainSpace.is_null())
     return {};
-  unsigned DomainDims = DomainSpace.dim(isl::dim::set).release();
+  unsigned DomainDims = unsignedFromIslSize(DomainSpace.dim(isl::dim::set));
   isl::space RangeSpace = Space.range().unwrap();
   isl::space Range1Space = RangeSpace.domain();
   if (Range1Space.is_null())
     return {};
-  unsigned Range1Dims = Range1Space.dim(isl::dim::set).release();
+  unsigned Range1Dims = unsignedFromIslSize(Range1Space.dim(isl::dim::set));
   isl::space Range2Space = RangeSpace.range();
   if (Range2Space.is_null())
     return {};
-  unsigned Range2Dims = Range2Space.dim(isl::dim::set).release();
+  unsigned Range2Dims = unsignedFromIslSize(Range2Space.dim(isl::dim::set));
 
   isl::space OutputSpace =
       DomainSpace.map_from_domain_and_range(Range1Space)
@@ -582,6 +582,11 @@
   return Result;
 }
 
+llvm::iota_range<unsigned> polly::rangeIslSize(unsigned Begin, isl::size End) {
+  unsigned UEnd = unsignedFromIslSize(End);
+  return llvm::seq<unsigned>(std::min(Begin, UEnd), UEnd);
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 static void foreachPoint(const isl::set &Set,
                          const std::function<void(isl::point P)> &F) {
@@ -606,17 +611,19 @@
   if (A.is_null() || B.is_null())
     return 0;
 
-  unsigned ALen = A.dim(isl::dim::set).release();
-  unsigned BLen = B.dim(isl::dim::set).release();
+  unsigned ALen = unsignedFromIslSize(A.dim(isl::dim::set));
+  unsigned BLen = unsignedFromIslSize(B.dim(isl::dim::set));
   unsigned Len = std::min(ALen, BLen);
 
   for (unsigned i = 0; i < Len; i += 1) {
     isl::basic_set ADim =
-        A.project_out(isl::dim::param, 0, A.dim(isl::dim::param).release())
+        A.project_out(isl::dim::param, 0,
+                      unsignedFromIslSize(A.dim(isl::dim::param)))
             .project_out(isl::dim::set, i + 1, ALen - i - 1)
             .project_out(isl::dim::set, 0, i);
     isl::basic_set BDim =
-        B.project_out(isl::dim::param, 0, B.dim(isl::dim::param).release())
+        B.project_out(isl::dim::param, 0,
+                      unsignedFromIslSize(B.dim(isl::dim::param)))
             .project_out(isl::dim::set, i + 1, BLen - i - 1)
             .project_out(isl::dim::set, 0, i);
 
@@ -687,8 +694,8 @@
     return NameCompare;
 
   if (ConsiderTupleLen) {
-    int LenCompare = BSpace.dim(isl::dim::set).release() -
-                     ASpace.dim(isl::dim::set).release();
+    int LenCompare = (int)unsignedFromIslSize(BSpace.dim(isl::dim::set)) -
+                     (int)unsignedFromIslSize(ASpace.dim(isl::dim::set));
     if (LenCompare != 0)
       return LenCompare;
   }
@@ -782,15 +789,17 @@
   OS << "\n}\n";
 }
 
-static void recursiveExpand(isl::basic_set BSet, int Dim, isl::set &Expanded) {
-  int Dims = BSet.dim(isl::dim::set).release();
+static void recursiveExpand(isl::basic_set BSet, unsigned Dim,
+                            isl::set &Expanded) {
+  unsigned Dims = unsignedFromIslSize(BSet.dim(isl::dim::set));
   if (Dim >= Dims) {
     Expanded = Expanded.unite(BSet);
     return;
   }
 
   isl::basic_set DimOnly =
-      BSet.project_out(isl::dim::param, 0, BSet.dim(isl::dim::param).release())
+      BSet.project_out(isl::dim::param, 0,
+                       unsignedFromIslSize(BSet.dim(isl::dim::param)))
           .project_out(isl::dim::set, Dim + 1, Dims - Dim - 1)
           .project_out(isl::dim::set, 0, Dim);
   if (!DimOnly.is_bounded()) {
Index: polly/lib/External/isl/include/isl/isl-noexceptions.h
===================================================================
--- polly/lib/External/isl/include/isl/isl-noexceptions.h
+++ polly/lib/External/isl/include/isl/isl-noexceptions.h
@@ -198,7 +198,6 @@
 };
 
 } // namespace isl
-
 #include <isl/id.h>
 #include <isl/space.h>
 #include <isl/val.h>
Index: polly/lib/Exchange/JSONExporter.cpp
===================================================================
--- polly/lib/Exchange/JSONExporter.cpp
+++ polly/lib/Exchange/JSONExporter.cpp
@@ -16,6 +16,7 @@
 #include "polly/Options.h"
 #include "polly/ScopInfo.h"
 #include "polly/ScopPass.h"
+#include "polly/Support/ISLTools.h"
 #include "polly/Support/ScopLocation.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/IR/Module.h"
@@ -230,8 +231,8 @@
     return false;
   }
 
-  unsigned OldContextDim = OldContext.dim(isl::dim::param).release();
-  unsigned NewContextDim = NewContext.dim(isl::dim::param).release();
+  unsigned OldContextDim = unsignedFromIslSize(OldContext.dim(isl::dim::param));
+  unsigned NewContextDim = unsignedFromIslSize(NewContext.dim(isl::dim::param));
 
   // Check if the imported context has the right number of parameters.
   if (OldContextDim != NewContextDim) {
Index: polly/lib/CodeGen/PPCGCodeGeneration.cpp
===================================================================
--- polly/lib/CodeGen/PPCGCodeGeneration.cpp
+++ polly/lib/CodeGen/PPCGCodeGeneration.cpp
@@ -22,6 +22,7 @@
 #include "polly/Options.h"
 #include "polly/ScopDetection.h"
 #include "polly/ScopInfo.h"
+#include "polly/Support/ISLTools.h"
 #include "polly/Support/SCEVValidator.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
@@ -1151,7 +1152,7 @@
 
   isl::set ZeroSet = isl::set::universe(Min.get_space());
 
-  for (long i = 0, n = Min.tuple_dim().release(); i < n; i++)
+  for (unsigned i : rangeIslSize(0, Min.tuple_dim()))
     ZeroSet = ZeroSet.fix_si(isl::dim::set, i, 0);
 
   if (Min.is_subset(ZeroSet)) {
@@ -1160,7 +1161,7 @@
 
   isl::ast_expr Result = isl::ast_expr::from_val(isl::val(Min.ctx(), 0));
 
-  for (long i = 0, n = Min.tuple_dim().release(); i < n; i++) {
+  for (unsigned i : rangeIslSize(0, Min.tuple_dim())) {
     if (i > 0) {
       isl::pw_aff Bound_I =
           isl::manage(isl_multi_pw_aff_get_pw_aff(Array->bound, i - 1));
@@ -2885,8 +2886,10 @@
     isl::pw_aff Val = isl::aff::var_on_domain(LS, isl::dim::set, 0);
     isl::pw_aff OuterMin = AccessSet.dim_min(0);
     isl::pw_aff OuterMax = AccessSet.dim_max(0);
-    OuterMin = OuterMin.add_dims(isl::dim::in, Val.dim(isl::dim::in).release());
-    OuterMax = OuterMax.add_dims(isl::dim::in, Val.dim(isl::dim::in).release());
+    OuterMin = OuterMin.add_dims(isl::dim::in,
+                                 unsignedFromIslSize(Val.dim(isl::dim::in)));
+    OuterMax = OuterMax.add_dims(isl::dim::in,
+                                 unsignedFromIslSize(Val.dim(isl::dim::in)));
     OuterMin = OuterMin.set_tuple_id(isl::dim::in, Array->getBasePtrId());
     OuterMax = OuterMax.set_tuple_id(isl::dim::in, Array->getBasePtrId());
 
@@ -2910,7 +2913,8 @@
 
       isl::pw_aff Val = isl::aff::var_on_domain(
           isl::local_space(Array->getSpace()), isl::dim::set, i);
-      PwAff = PwAff.add_dims(isl::dim::in, Val.dim(isl::dim::in).release());
+      PwAff = PwAff.add_dims(isl::dim::in,
+                             unsignedFromIslSize(Val.dim(isl::dim::in)));
       PwAff = PwAff.set_tuple_id(isl::dim::in, Val.get_tuple_id(isl::dim::in));
       isl::set Set = PwAff.gt_set(Val);
       Extent = Set.intersect(Extent);
Index: polly/lib/CodeGen/BlockGenerators.cpp
===================================================================
--- polly/lib/CodeGen/BlockGenerators.cpp
+++ polly/lib/CodeGen/BlockGenerators.cpp
@@ -17,6 +17,7 @@
 #include "polly/CodeGen/RuntimeDebugBuilder.h"
 #include "polly/Options.h"
 #include "polly/ScopInfo.h"
+#include "polly/Support/ISLTools.h"
 #include "polly/Support/ScopHelper.h"
 #include "polly/Support/VirtualInstruction.h"
 #include "llvm/Analysis/LoopInfo.h"
@@ -688,8 +689,7 @@
   Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "("));
 
   // Add the coordinate of the statement instance.
-  int DomDims = ScheduleMultiPwAff.dim(isl::dim::out).release();
-  for (int i = 0; i < DomDims; i += 1) {
+  for (unsigned i : rangeIslSize(0, ScheduleMultiPwAff.dim(isl::dim::out))) {
     if (i > 0)
       Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ","));
 
Index: polly/lib/Analysis/ScopInfo.cpp
===================================================================
--- polly/lib/Analysis/ScopInfo.cpp
+++ polly/lib/Analysis/ScopInfo.cpp
@@ -112,7 +112,7 @@
 STATISTIC(NumSingletonWritesInLoops,
           "Number of singleton writes nested in affine loops after ScopInfo");
 
-int const polly::MaxDisjunctsInDomain = 20;
+unsigned const polly::MaxDisjunctsInDomain = 20;
 
 // The number of disjunct in the context after which we stop to add more
 // disjuncts. This parameter is there to avoid exponential growth in the
@@ -443,9 +443,10 @@
   isl::space AccessSpace = AccessRelation.get_space().range();
   isl::ctx Ctx = ArraySpace.ctx();
 
-  auto DimsArray = ArraySpace.dim(isl::dim::set).release();
-  auto DimsAccess = AccessSpace.dim(isl::dim::set).release();
-  auto DimsMissing = DimsArray - DimsAccess;
+  unsigned DimsArray = unsignedFromIslSize(ArraySpace.dim(isl::dim::set));
+  unsigned DimsAccess = unsignedFromIslSize(AccessSpace.dim(isl::dim::set));
+  assert(DimsArray >= DimsAccess);
+  unsigned DimsMissing = DimsArray - DimsAccess;
 
   auto *BB = getStatement()->getEntryBlock();
   auto &DL = BB->getModule()->getDataLayout();
@@ -455,10 +456,10 @@
   isl::map Map = isl::map::from_domain_and_range(
       isl::set::universe(AccessSpace), isl::set::universe(ArraySpace));
 
-  for (auto i : seq<isl_size>(0, DimsMissing))
+  for (auto i : seq<unsigned>(0, DimsMissing))
     Map = Map.fix_si(isl::dim::out, i, 0);
 
-  for (auto i : seq<isl_size>(DimsMissing, DimsArray))
+  for (auto i : seq<unsigned>(DimsMissing, DimsArray))
     Map = Map.equate(isl::dim::in, i - DimsMissing, isl::dim::out, i);
 
   AccessRelation = AccessRelation.apply_range(Map);
@@ -497,9 +498,10 @@
   if (ElemBytes > ArrayElemSize) {
     assert(ElemBytes % ArrayElemSize == 0 &&
            "Loaded element size should be multiple of canonical element size");
+    assert(DimsArray >= 1);
     isl::map Map = isl::map::from_domain_and_range(
         isl::set::universe(ArraySpace), isl::set::universe(ArraySpace));
-    for (auto i : seq<isl_size>(0, DimsArray - 1))
+    for (auto i : seq<unsigned>(0, DimsArray - 1))
       Map = Map.equate(isl::dim::in, i, isl::dim::out, i);
 
     isl::constraint C;
@@ -1008,10 +1010,10 @@
 
   Stride = getStride(Schedule);
   StrideX = isl::set::universe(Stride.get_space());
-  for (auto i : seq<isl_size>(0, StrideX.tuple_dim().release() - 1))
+  int Size = unsignedFromIslSize(StrideX.tuple_dim());
+  for (auto i : seq<int>(0, Size - 1))
     StrideX = StrideX.fix_si(isl::dim::set, i, 0);
-  StrideX = StrideX.fix_si(isl::dim::set, StrideX.tuple_dim().release() - 1,
-                           StrideWidth);
+  StrideX = StrideX.fix_si(isl::dim::set, Size - 1, StrideWidth);
   IsStrideX = Stride.is_subset(StrideX);
 
   return IsStrideX;
@@ -1070,9 +1072,9 @@
 
   // Check whether access dimensions correspond to number of dimensions of the
   // accesses array.
-  isl_size Dims = SAI->getNumberOfDimensions();
-  assert(NewAccessSpace.dim(isl::dim::set).release() == Dims &&
-         "Access dims must match array dims");
+  unsigned Dims = SAI->getNumberOfDimensions();
+  unsigned SpaceSize = unsignedFromIslSize(NewAccessSpace.dim(isl::dim::set));
+  assert(SpaceSize == Dims && "Access dims must match array dims");
 #endif
 
   NewAccess = NewAccess.gist_params(getStatement()->getParent()->getContext());
Index: polly/lib/Analysis/ScopBuilder.cpp
===================================================================
--- polly/lib/Analysis/ScopBuilder.cpp
+++ polly/lib/Analysis/ScopBuilder.cpp
@@ -73,7 +73,7 @@
 // More complex access ranges will result in very high compile time and are also
 // unlikely to result in good code. This value is very high and should only
 // trigger for corner cases (e.g., the "dct_luma" function in h264, SPEC2006).
-static int const MaxDimensionsInAccessRange = 9;
+static unsigned const MaxDimensionsInAccessRange = 9;
 
 static cl::opt<bool, true> XModelReadOnlyScalars(
     "polly-analyze-read-only-scalars",
@@ -108,7 +108,7 @@
     cl::desc("The maximal number of arrays to compare in each alias group."),
     cl::Hidden, cl::ZeroOrMore, cl::init(20), cl::cat(PollyCategory));
 
-static cl::opt<int> RunTimeChecksMaxAccessDisjuncts(
+static cl::opt<unsigned> RunTimeChecksMaxAccessDisjuncts(
     "polly-rtc-max-array-disjuncts",
     cl::desc("The maximal number of disjunts allowed in memory accesses to "
              "to build RTCs."),
@@ -198,8 +198,8 @@
 static isl::map createNextIterationMap(isl::space SetSpace, unsigned Dim) {
   isl::space MapSpace = SetSpace.map_from_set();
   isl::map NextIterationMap = isl::map::universe(MapSpace);
-  for (auto u : seq<isl_size>(0, NextIterationMap.domain_tuple_dim().release()))
-    if (u != (isl_size)Dim)
+  for (auto u : rangeIslSize(0, NextIterationMap.domain_tuple_dim()))
+    if (u != Dim)
       NextIterationMap =
           NextIterationMap.equate(isl::dim::in, u, isl::dim::out, u);
   isl::constraint C =
@@ -226,10 +226,10 @@
 ///          both with regards to the dimension @p Dim.
 static std::pair<isl::set, isl::set> partitionSetParts(isl::set S,
                                                        unsigned Dim) {
-  for (unsigned u = 0, e = S.tuple_dim().release(); u < e; u++)
+  for (unsigned u : rangeIslSize(0, S.tuple_dim()))
     S = S.lower_bound_si(isl::dim::set, u, 0);
 
-  unsigned NumDimsS = S.tuple_dim().release();
+  unsigned NumDimsS = unsignedFromIslSize(S.tuple_dim());
   isl::set OnlyDimS = S;
 
   // Remove dimensions that are greater than Dim as they are not interesting.
@@ -323,8 +323,8 @@
     Dom = Dom.add_dims(isl::dim::set, 1);
   } else {
     assert(OldDepth > NewDepth);
-    int Diff = OldDepth - NewDepth;
-    int NumDim = Dom.tuple_dim().release();
+    unsigned Diff = OldDepth - NewDepth;
+    unsigned NumDim = unsignedFromIslSize(Dom.tuple_dim());
     assert(NumDim >= Diff);
     Dom = Dom.project_out(isl::dim::set, NumDim - Diff, Diff);
   }
@@ -540,13 +540,13 @@
 
   isl_set *AlternativeCondSet = nullptr;
   bool TooComplex =
-      isl_set_n_basic_set(ConsequenceCondSet) >= MaxDisjunctsInDomain;
+      isl_set_n_basic_set(ConsequenceCondSet) >= (int)MaxDisjunctsInDomain;
 
   if (!TooComplex) {
     AlternativeCondSet = isl_set_subtract(isl_set_copy(Domain),
                                           isl_set_copy(ConsequenceCondSet));
     TooComplex =
-        isl_set_n_basic_set(AlternativeCondSet) >= MaxDisjunctsInDomain;
+        isl_set_n_basic_set(AlternativeCondSet) >= (int)MaxDisjunctsInDomain;
   }
 
   if (TooComplex) {
@@ -910,7 +910,7 @@
       continue;
     isl::set Domain = scop->getDomainConditions(BB);
 
-    scop->updateMaxLoopDepth(Domain.tuple_dim().release());
+    scop->updateMaxLoopDepth(unsignedFromIslSize(Domain.tuple_dim()));
 
     auto *BBLoop = getRegionNodeLoop(RN, LI);
     // Propagate the domain from BB directly to blocks that have a superset
@@ -984,7 +984,7 @@
 
       // Check if the maximal number of domain disjunctions was reached.
       // In case this happens we will clean up and bail.
-      if (SuccDomain.n_basic_set().release() < MaxDisjunctsInDomain)
+      if (unsignedFromIslSize(SuccDomain.n_basic_set()) < MaxDisjunctsInDomain)
         continue;
 
       scop->invalidate(COMPLEXITY, DebugLoc());
@@ -1064,7 +1064,8 @@
 
       // Check if the maximal number of domain disjunctions was reached.
       // In case this happens we will bail.
-      if (SuccInvalidDomain.n_basic_set().release() < MaxDisjunctsInDomain)
+      if (unsignedFromIslSize(SuccInvalidDomain.n_basic_set()) <
+          MaxDisjunctsInDomain)
         continue;
 
       InvalidDomainMap.erase(BB);
@@ -1155,15 +1156,15 @@
 //               mapping.
 // @param N      The dimension to map to.
 // @returns      A mapping from USet to its N-th dimension.
-static isl::multi_union_pw_aff mapToDimension(isl::union_set USet, int N) {
-  assert(N >= 0);
+static isl::multi_union_pw_aff mapToDimension(isl::union_set USet, unsigned N) {
   assert(!USet.is_null());
   assert(!USet.is_empty());
 
   auto Result = isl::union_pw_multi_aff::empty(USet.get_space());
 
   for (isl::set S : USet.get_set_list()) {
-    int Dim = S.tuple_dim().release();
+    unsigned Dim = unsignedFromIslSize(S.tuple_dim());
+    assert(Dim >= N);
     auto PMA = isl::pw_multi_aff::project_out_map(S.get_space(), isl::dim::set,
                                                   N, Dim - N);
     if (N > 1)
@@ -2212,8 +2213,8 @@
     isl::map Transform = isl::map::universe(Array->getSpace().map_from_set());
 
     std::vector<int> Int;
-    int Dims = Elements.tuple_dim().release();
-    for (int i = 0; i < Dims; i++) {
+    unsigned Dims = unsignedFromIslSize(Elements.tuple_dim());
+    for (unsigned i = 0; i < Dims; i++) {
       isl::set DimOnly = isl::set(Elements).project_out(isl::dim::set, 0, i);
       DimOnly = DimOnly.project_out(isl::dim::set, 1, Dims - i - 1);
       DimOnly = DimOnly.lower_bound_si(isl::dim::set, 0, 0);
@@ -2226,7 +2227,7 @@
         continue;
       }
 
-      if (DimHull.dim(isl::dim::div).release() == 1) {
+      if (unsignedFromIslSize(DimHull.dim(isl::dim::div)) == 1) {
         isl::aff Diff = DimHull.get_div(0);
         isl::val Val = Diff.get_denominator_val();
 
@@ -2625,11 +2626,11 @@
 ///
 /// @returns True if the access range is too complex.
 static bool isAccessRangeTooComplex(isl::set AccessRange) {
-  int NumTotalDims = 0;
+  unsigned NumTotalDims = 0;
 
   for (isl::basic_set BSet : AccessRange.get_basic_set_list()) {
-    NumTotalDims += BSet.dim(isl::dim::div).release();
-    NumTotalDims += BSet.dim(isl::dim::set).release();
+    NumTotalDims += unsignedFromIslSize(BSet.dim(isl::dim::div));
+    NumTotalDims += unsignedFromIslSize(BSet.dim(isl::dim::set));
   }
 
   if (NumTotalDims > MaxDimensionsInAccessRange)
@@ -2658,8 +2659,9 @@
 
   isl::set UserContext = isl::set(scop->getIslCtx(), UserContextStr.c_str());
   isl::space Space = scop->getParamSpace();
-  if (Space.dim(isl::dim::param).release() !=
-      UserContext.dim(isl::dim::param).release()) {
+  isl::size SpaceParams = Space.dim(isl::dim::param);
+  if (unsignedFromIslSize(SpaceParams) !=
+      unsignedFromIslSize(UserContext.dim(isl::dim::param))) {
     std::string SpaceStr = stringFromIslObj(Space, "null");
     errs() << "Error: the context provided in -polly-context has not the same "
            << "number of dimensions than the computed context. Due to this "
@@ -2668,7 +2670,7 @@
     return;
   }
 
-  for (auto i : seq<isl_size>(0, Space.dim(isl::dim::param).release())) {
+  for (auto i : rangeIslSize(0, SpaceParams)) {
     std::string NameContext =
         scop->getContext().get_dim_name(isl::dim::param, i);
     std::string NameUserContext = UserContext.get_dim_name(isl::dim::param, i);
@@ -2752,7 +2754,8 @@
     return WrittenCtx;
 
   WrittenCtx = WrittenCtx.remove_divs();
-  bool TooComplex = WrittenCtx.n_basic_set().release() >= MaxDisjunctsInDomain;
+  bool TooComplex =
+      unsignedFromIslSize(WrittenCtx.n_basic_set()) >= MaxDisjunctsInDomain;
   if (TooComplex || !isRequiredInvariantLoad(LI))
     return {};
 
@@ -2818,7 +2821,7 @@
   isl::set DomainCtx = Stmt.getDomain().params();
   DomainCtx = DomainCtx.subtract(StmtInvalidCtx);
 
-  if (DomainCtx.n_basic_set().release() >= MaxDisjunctsInDomain) {
+  if (unsignedFromIslSize(DomainCtx.n_basic_set()) >= MaxDisjunctsInDomain) {
     auto *AccInst = InvMAs.front().MA->getAccessInstruction();
     scop->invalidate(COMPLEXITY, AccInst->getDebugLoc(), AccInst->getParent());
     return;
@@ -3094,7 +3097,7 @@
   Set = Set.remove_divs();
   polly::simplify(Set);
 
-  if (Set.n_basic_set().release() > RunTimeChecksMaxAccessDisjuncts)
+  if (unsignedFromIslSize(Set.n_basic_set()) > RunTimeChecksMaxAccessDisjuncts)
     Set = Set.simple_hull();
 
   // Restrict the number of parameters involved in the access as the lexmin/
@@ -3128,14 +3131,18 @@
   MinPMA = MinPMA.coalesce();
   MaxPMA = MaxPMA.coalesce();
 
+  if (MaxPMA.is_null())
+    return false;
+
+  unsigned MaxOutputSize = unsignedFromIslSize(MaxPMA.dim(isl::dim::out));
+
   // Adjust the last dimension of the maximal access by one as we want to
   // enclose the accessed memory region by MinPMA and MaxPMA. The pointer
   // we test during code generation might now point after the end of the
   // allocated array but we will never dereference it anyway.
-  assert((MaxPMA.is_null() || MaxPMA.dim(isl::dim::out).release()) &&
-         "Assumed at least one output dimension");
+  assert(MaxOutputSize >= 1 && "Assumed at least one output dimension");
 
-  Pos = MaxPMA.dim(isl::dim::out).release() - 1;
+  Pos = MaxOutputSize - 1;
   LastDimAff = MaxPMA.at(Pos);
   OneAff = isl::aff(isl::local_space(LastDimAff.get_domain_space()));
   OneAff = OneAff.add_constant_si(1);
@@ -3176,7 +3183,8 @@
 
 static isl::set getAccessDomain(MemoryAccess *MA) {
   isl::set Domain = MA->getStatement()->getDomain();
-  Domain = Domain.project_out(isl::dim::set, 0, Domain.tuple_dim().release());
+  Domain = Domain.project_out(isl::dim::set, 0,
+                              unsignedFromIslSize(Domain.tuple_dim()));
   return Domain.reset_tuple_id();
 }
 
Index: polly/lib/Analysis/DependenceInfo.cpp
===================================================================
--- polly/lib/Analysis/DependenceInfo.cpp
+++ polly/lib/Analysis/DependenceInfo.cpp
@@ -190,7 +190,7 @@
 
 /// Fix all dimension of @p Zero to 0 and add it to @p user
 static void fixSetToZero(isl::set Zero, isl::union_set *User) {
-  for (auto i : seq<isl_size>(0, Zero.tuple_dim().release()))
+  for (auto i : rangeIslSize(0, Zero.tuple_dim()))
     Zero = Zero.fix_si(isl::dim::set, i, 0);
   *User = User->unite(Zero);
 }
@@ -680,7 +680,7 @@
   Dependences = Dependences.apply_range(Schedule);
 
   isl::set Zero = isl::set::universe(ScheduleSpace);
-  for (auto i : seq<isl_size>(0, Zero.tuple_dim().release()))
+  for (auto i : rangeIslSize(0, Zero.tuple_dim()))
     Zero = Zero.fix_si(isl::dim::set, i, 0);
 
   isl::union_set UDeltas = Dependences.deltas();
Index: polly/include/polly/Support/ISLTools.h
===================================================================
--- polly/include/polly/Support/ISLTools.h
+++ polly/include/polly/Support/ISLTools.h
@@ -14,8 +14,30 @@
 #ifndef POLLY_ISLTOOLS_H
 #define POLLY_ISLTOOLS_H
 
+#include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/iterator.h"
 #include "isl/isl-noexceptions.h"
+#include <cassert>
+
+/// In debug builds assert that the @p Size is valid, in non-debug builds
+/// disable the mandatory state checking but do not enforce the error checking.
+inline void islAssert(const isl::size &Size) {
+#ifdef NDEBUG
+  // Don't force error checking in non-debug builds.
+  Size.is_error();
+#else
+  // Assert on error in debug builds.
+  assert(!Size.is_error());
+#endif
+}
+
+/// Check that @p Size is valid (only on debug builds) and cast it to unsigned.
+/// Cast the @p Size to unsigned. If the @p Size is not valid (Size.is_error()
+/// == true) then an assert and an abort are triggered.
+inline unsigned unsignedFromIslSize(const isl::size &Size) {
+  islAssert(Size);
+  return static_cast<unsigned>(Size);
+}
 
 namespace isl {
 inline namespace noexceptions {
@@ -160,7 +182,7 @@
 /// The implementation currently returns the maximum number of dimensions it
 /// encounters, if different, and 0 if none is encountered. However, most other
 /// code will most likely fail if one of these happen.
-isl_size getNumScatterDims(const isl::union_map &Schedule);
+unsigned getNumScatterDims(const isl::union_map &Schedule);
 
 /// Return the scatter space of a @p Schedule.
 ///
@@ -498,6 +520,13 @@
 /// value. Otherwise, return NaN.
 isl::val getConstant(isl::pw_aff PwAff, bool Max, bool Min);
 
+/// Check that @p End is valid and return an iterator from @p Begin to @p End
+///
+/// Use case example:
+///   for (unsigned i : rangeIslSize(0, Map.domain_tuple_dim()))
+///     // do stuff
+llvm::iota_range<unsigned> rangeIslSize(unsigned Begin, isl::size End);
+
 /// Dump a description of the argument to llvm::errs().
 ///
 /// In contrast to isl's dump function, there are a few differences:
Index: polly/include/polly/ScopInfo.h
===================================================================
--- polly/include/polly/ScopInfo.h
+++ polly/include/polly/ScopInfo.h
@@ -81,7 +81,7 @@
 // The maximal number of basic sets we allow during domain construction to
 // be created. More complex scops will result in very high compile time and
 // are also unlikely to result in good code.
-extern int const MaxDisjunctsInDomain;
+extern unsigned const MaxDisjunctsInDomain;
 
 /// The different memory kinds used in Polly.
 ///
Index: polly/include/polly/ScheduleTreeTransform.h
===================================================================
--- polly/include/polly/ScheduleTreeTransform.h
+++ polly/include/polly/ScheduleTreeTransform.h
@@ -13,6 +13,7 @@
 #ifndef POLLY_SCHEDULETREETRANSFORM_H
 #define POLLY_SCHEDULETREETRANSFORM_H
 
+#include "polly/Support/ISLTools.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "isl/isl-noexceptions.h"
@@ -147,8 +148,7 @@
 
   /// By default, recursively visit the child nodes.
   RetTy visitNode(isl::schedule_node Node, Args... args) {
-    isl_size NumChildren = Node.n_children().release();
-    for (isl_size i = 0; i < NumChildren; i += 1)
+    for (unsigned i : rangeIslSize(0, Node.n_children()))
       getDerived().visit(Node.child(i), std::forward<Args>(args)...);
     return RetTy();
   }
@@ -208,7 +208,7 @@
 ///                      belong to the current band node.
 /// @param OutDimsNum    A number of dimensions that should belong to
 ///                      the current band node.
-isl::union_set getIsolateOptions(isl::set IsolateDomain, isl_size OutDimsNum);
+isl::union_set getIsolateOptions(isl::set IsolateDomain, unsigned OutDimsNum);
 
 /// Create an isl::union_set, which describes the specified option for the
 /// dimension of the current node.
