[llvm] r329111 - [LoopInterchange] Add remark for calls preventing interchanging.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 13:54:04 PDT 2018


Author: fhahn
Date: Tue Apr  3 13:54:04 2018
New Revision: 329111

URL: http://llvm.org/viewvc/llvm-project?rev=329111&view=rev
Log:
[LoopInterchange] Add remark for calls preventing interchanging.

It also updates test/Transforms/LoopInterchange/call-instructions.ll
to use accesses where we can prove dependence after D35430.


Reviewers: sebpop, karthikthecool, blitz.opensource

Reviewed By: sebpop

Differential Revision: https://reviews.llvm.org/D45206

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
    llvm/trunk/test/Transforms/LoopInterchange/call-instructions.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp?rev=329111&r1=329110&r2=329111&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp Tue Apr  3 13:54:04 2018
@@ -985,6 +985,13 @@ bool LoopInterchangeLegality::canInterch
           continue;
         DEBUG(dbgs() << "Loops with call instructions cannot be interchanged "
                      << "safely.");
+        ORE->emit([&]() {
+          return OptimizationRemarkMissed(DEBUG_TYPE, "CallInst",
+                                          CI->getDebugLoc(),
+                                          CI->getParent())
+                 << "Cannot interchange loops due to call instruction.";
+        });
+
         return false;
       }
 

Modified: llvm/trunk/test/Transforms/LoopInterchange/call-instructions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopInterchange/call-instructions.ll?rev=329111&r1=329110&r2=329111&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopInterchange/call-instructions.ll (original)
+++ llvm/trunk/test/Transforms/LoopInterchange/call-instructions.ll Tue Apr  3 13:54:04 2018
@@ -1,5 +1,5 @@
-; REQUIRES: asserts
-; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s
+; RUN: opt < %s -basicaa -loop-interchange -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t
+; RUN: FileCheck --input-file=%t %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
@@ -13,42 +13,37 @@ declare void @bar(i64 %a) readnone
 ;; Not safe to interchange, because the called function `foo` is not marked as
 ;; readnone, so it could introduce dependences.
 ;;
-;;  for(int i=0;i<N;i++) {
-;;    for(int j=1;j<N;j++) {
+;;  for(int i=0;i<100;i++) {
+;;    for(int j=1;j<100;j++) {
 ;;      foo(i);
 ;;      A[j][i] = A[j][i]+k;
 ;;    }
 ;; }
 
-; CHECK: Not interchanging loops. Cannot prove legality.
+; CHECK: --- !Missed
+; CHECK-NEXT: Pass:            loop-interchange
+; CHECK-NEXT: Name:            CallInst
+; CHECK-NEXT: Function:        interchange_01
+; CHECK-NEXT: Args:
+; CHECK-NEXT  - String:          Cannot interchange loops due to call instruction.
 
-define void @interchange_01(i32 %k, i32 %N) {
+define void @interchange_01(i32 %k) {
 entry:
-  %cmp21 = icmp sgt i32 %N, 0
-  br i1 %cmp21, label %for1.ph, label %exit
-
-for1.ph:
-  %cmp219 = icmp sgt i32 %N, 1
-  %0 = add i32 %N, -1
   br label %for1.header
 
 for1.header:
-  %indvars.iv23 = phi i64 [ 0, %for1.ph ], [ %indvars.iv.next24, %for1.inc10 ]
-  br i1 %cmp219, label %for2.ph, label %for1.inc10
-
-for2.ph:
+  %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
   br label %for2
 
 for2:
-  %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for2.ph ]
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
   call void @foo(i64 %indvars.iv23)
   %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
-  %1 = load i32, i32* %arrayidx5
-  %add = add nsw i32 %1, %k
+  %lv = load i32, i32* %arrayidx5
+  %add = add nsw i32 %lv, %k
   store i32 %add, i32* %arrayidx5
   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
-  %lftr.wideiv = trunc i64 %indvars.iv to i32
-  %exitcond = icmp eq i32 %lftr.wideiv, %0
+  %exitcond = icmp eq i64 %indvars.iv, 99
   br i1 %exitcond, label %for2.loopexit , label %for2
 
 for2.loopexit:
@@ -56,8 +51,7 @@ for2.loopexit:
 
 for1.inc10:
   %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
-  %lftr.wideiv25 = trunc i64 %indvars.iv23 to i32
-  %exitcond26 = icmp eq i32 %lftr.wideiv25, %0
+  %exitcond26 = icmp eq i64 %indvars.iv23, 99
   br i1 %exitcond26, label %for1.loopexit, label %for1.header
 
 for1.loopexit:
@@ -71,42 +65,38 @@ exit:
 ;; Safe to interchange, because the called function `bar` is marked as readnone,
 ;; so it cannot introduce dependences.
 ;;
-;;  for(int i=0;i<N;i++) {
-;;    for(int j=1;j<N;j++) {
+;;  for(int i=0;i<100;i++) {
+;;    for(int j=1;j<100;j++) {
 ;;      bar(i);
 ;;      A[j][i] = A[j][i]+k;
 ;;    }
 ;; }
 
-; CHECK: Not interchanging loops. Cannot prove legality.
+; CHECK: --- !Passed
+; CHECK-NEXT: Pass:            loop-interchange
+; CHECK-NEXT: Name:            Interchanged
+; CHECK-NEXT: Function:        interchange_02
+; CHECK-NEXT: Args:
+; CHECK-NEXT:   - String:          Loop interchanged with enclosing loop.
+; CHECK-NEXT: ...
 
-define void @interchange_02(i32 %k, i32 %N) {
+define void @interchange_02(i32 %k) {
 entry:
-  %cmp21 = icmp sgt i32 %N, 0
-  br i1 %cmp21, label %for1.ph, label %exit
-
-for1.ph:
-  %cmp219 = icmp sgt i32 %N, 1
-  %0 = add i32 %N, -1
   br label %for1.header
 
 for1.header:
-  %indvars.iv23 = phi i64 [ 0, %for1.ph ], [ %indvars.iv.next24, %for1.inc10 ]
-  br i1 %cmp219, label %for2.ph, label %for1.inc10
-
-for2.ph:
+  %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
   br label %for2
 
 for2:
-  %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for2.ph ]
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
   call void @bar(i64 %indvars.iv23)
   %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
-  %1 = load i32, i32* %arrayidx5
-  %add = add nsw i32 %1, %k
+  %lv = load i32, i32* %arrayidx5
+  %add = add nsw i32 %lv, %k
   store i32 %add, i32* %arrayidx5
   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
-  %lftr.wideiv = trunc i64 %indvars.iv to i32
-  %exitcond = icmp eq i32 %lftr.wideiv, %0
+  %exitcond = icmp eq i64 %indvars.iv, 99
   br i1 %exitcond, label %for2.loopexit , label %for2
 
 for2.loopexit:
@@ -114,8 +104,7 @@ for2.loopexit:
 
 for1.inc10:
   %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
-  %lftr.wideiv25 = trunc i64 %indvars.iv23 to i32
-  %exitcond26 = icmp eq i32 %lftr.wideiv25, %0
+  %exitcond26 = icmp eq i64 %indvars.iv23, 99
   br i1 %exitcond26, label %for1.loopexit, label %for1.header
 
 for1.loopexit:




More information about the llvm-commits mailing list