diff --git a/loopy/schedule.py b/loopy/schedule.py
index 419672a96dbadba22d58e80e8a198e082447ba1e..c884a2bfd10db6055200f38f7893f2be0c654e4b 100644
--- a/loopy/schedule.py
+++ b/loopy/schedule.py
@@ -903,8 +903,9 @@ def insert_barriers(kernel, schedule, reverse, kind, level=0):
             last_barrier_index = None
 
             for j, sub_sched_item in enumerate(subresult):
-                if (isinstance(sched_item, Barrier) and
-                        barrier_kind_more_or_equally_global(sched_item.kind, kind)):
+                if (isinstance(sub_sched_item, Barrier) and
+                        barrier_kind_more_or_equally_global(
+                            sub_sched_item.kind, kind)):
 
                     seen_barrier()
                     last_barrier_index = j