[PATCH] D43236: [LoopInterchange] Loops with empty dependency matrix are safe.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 07:23:50 PST 2018


fhahn created this revision.
fhahn added reviewers: karthikthecool, mcrosier.

The dependency matrix is only empty if no conflicting load/store
instructions have been found. In that case, it is safe to interchange.

For the LLVM test-suite, after this change around 1900 loops are
interchanged, whereas it is 15 before this change. On cortex-a57,
this gives an improvement of -0.57% on the geomean execution
time of SPEC2006, SPEC2000 and the test-suite. There are a
few regressions, but I think we can improve on those by making
the cost model better.


https://reviews.llvm.org/D43236

Files:
  lib/Transforms/Scalar/CallSiteSplitting.cpp
  lib/Transforms/Scalar/LoopInterchange.cpp
  test/Transforms/LoopInterchange/interchange-no-deps.ll


Index: test/Transforms/LoopInterchange/interchange-no-deps.ll
===================================================================
--- /dev/null
+++ test/Transforms/LoopInterchange/interchange-no-deps.ll
@@ -0,0 +1,44 @@
+; RUN: opt < %s -loop-interchange -simplifycfg -S | FileCheck %s
+
+; no_deps_interchange just access a single nested array and can be interchange.
+define i32 @no_deps_interchange([1024 x i32]* nocapture %Arr, i32 %k) local_unnamed_addr #0 {
+entry:
+  br label %for.body
+
+for.body:                                         ; preds = %entry, %for.cond.cleanup3
+  %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for.cond.cleanup3 ]
+  br label %for.body4
+
+for.body4:                                        ; preds = %for.body, %for.body4
+  %indvars.iv = phi i64 [ 0, %for.body ], [ %indvars.iv.next, %for.body4 ]
+  %arrayidx6 = getelementptr inbounds [1024 x i32], [1024 x i32]* %Arr, i64 %indvars.iv, i64 %indvars.iv19
+  store i32 0, i32* %arrayidx6, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp ne i64 %indvars.iv.next, 1024
+  br i1 %exitcond, label %for.body4, label %for.cond.cleanup3
+
+for.cond.cleanup3:                                ; preds = %for.body4
+  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
+  %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
+  br i1 %exitcond21, label %for.body, label %for.cond.cleanup
+
+
+for.cond.cleanup:                                 ; preds = %for.cond.cleanup3
+  ret i32 0
+}
+
+; CHECK-LABEL: @no_deps_interchange
+; CHECK-LABEL: entry:
+; CHECK-NEXT: br label %for.body4
+
+; CHECK-LABEL: for.body:                                         ; preds = %for.body4, %for.body
+; CHECK: %indvars.iv19 = phi i64 [ %indvars.iv.next20, %for.body ], [ 0, %for.body4 ]
+; CHECK: br i1 %exitcond21, label %for.body, label %for.body4.split
+
+; CHECK-LABEL: for.body4:                                        ; preds = %entry, %for.body4.split
+; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body4.split ], [ 0, %entry ]
+; CHECK: br label %for.body
+
+; CHECK-LABEL: for.body4.split:                                  ; preds = %for.body
+; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+; CHECK: br i1 %exitcond, label %for.body4, label %for.cond.cleanup
Index: lib/Transforms/Scalar/LoopInterchange.cpp
===================================================================
--- lib/Transforms/Scalar/LoopInterchange.cpp
+++ lib/Transforms/Scalar/LoopInterchange.cpp
@@ -173,9 +173,6 @@
     }
   }
 
-  // We don't have a DepMatrix to check legality return false.
-  if (DepMatrix.empty())
-    return false;
   return true;
 }
 
Index: lib/Transforms/Scalar/CallSiteSplitting.cpp
===================================================================
--- lib/Transforms/Scalar/CallSiteSplitting.cpp
+++ lib/Transforms/Scalar/CallSiteSplitting.cpp
@@ -296,10 +296,10 @@
       CallPN->addIncoming(NewCI, SplitBlock);
   }
 
-  auto *OriginalBegin = &*TailBB->begin();
+  auto OriginalBegin = TailBB->begin();
   // Replace users of the original call with a PHI mering call-sites split.
   if (CallPN) {
-    CallPN->insertBefore(OriginalBegin);
+    CallPN->insertBefore(&*OriginalBegin);
     Instr->replaceAllUsesWith(CallPN);
   }
 
@@ -327,13 +327,9 @@
     }
     CurrentI->eraseFromParent();
     // We are done once we handled the first original instruction in TailBB.
-    if (CurrentI == OriginalBegin)
+    if (CurrentI == &*OriginalBegin)
       break;
   }
-
-  ValueToValueMaps[0].clear();
-  ValueToValueMaps[1].clear();
-
   NumCallSiteSplit++;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43236.134030.patch
Type: text/x-patch
Size: 3609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/2c5d992f/attachment.bin>


More information about the llvm-commits mailing list