38 changes: 26 additions & 12 deletions llvm/test/Analysis/DependenceAnalysis/ExactSIV.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s -analyze -basicaa -da | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s

; ModuleID = 'ExactSIV.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
Expand All @@ -13,8 +13,9 @@ define void @exact0(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact0
; CHECK: da analyze - none!
; CHECK: da analyze - flow [<=|<]!
; CHECK: da analyze - flow [>]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -50,6 +51,7 @@ define void @exact1(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact1
; CHECK: da analyze - none!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -88,6 +90,7 @@ define void @exact2(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact2
; CHECK: da analyze - none!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -124,8 +127,9 @@ define void @exact3(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact3
; CHECK: da analyze - none!
; CHECK: da analyze - flow [>]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -160,8 +164,9 @@ define void @exact4(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact4
; CHECK: da analyze - none!
; CHECK: da analyze - flow [>]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -196,8 +201,9 @@ define void @exact5(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact5
; CHECK: da analyze - none!
; CHECK: da analyze - flow [=>|<]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -232,8 +238,9 @@ define void @exact6(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact6
; CHECK: da analyze - none!
; CHECK: da analyze - flow [=>|<]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -268,8 +275,9 @@ define void @exact7(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact7
; CHECK: da analyze - none!
; CHECK: da analyze - flow [*|<]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -304,6 +312,7 @@ define void @exact8(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact8
; CHECK: da analyze - none!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -340,8 +349,9 @@ define void @exact9(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact9
; CHECK: da analyze - none!
; CHECK: da analyze - flow [>]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -376,8 +386,9 @@ define void @exact10(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact10
; CHECK: da analyze - none!
; CHECK: da analyze - flow [>]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -412,8 +423,9 @@ define void @exact11(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact11
; CHECK: da analyze - none!
; CHECK: da analyze - flow [=>|<]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -448,8 +460,9 @@ define void @exact12(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact12
; CHECK: da analyze - none!
; CHECK: da analyze - flow [=>|<]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -484,8 +497,9 @@ define void @exact13(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.body

; CHECK-LABEL: exact13
; CHECK: da analyze - none!
; CHECK: da analyze - flow [*|<]!
; CHECK: da analyze - flow [<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down
103 changes: 11 additions & 92 deletions llvm/test/Analysis/DependenceAnalysis/GCD.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
; RUN: opt < %s -analyze -basicaa -da -da-delinearize=false | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s -check-prefix=DELIN

; ModuleID = 'GCD.bc'
Expand All @@ -15,15 +14,7 @@ define void @gcd0(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: 'Dependence Analysis' for function 'gcd0'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - flow [=> *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

; DELIN: 'Dependence Analysis' for function 'gcd0'
; DELIN-LABEL: gcd0
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - flow [=> *|<]!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -76,15 +67,7 @@ define void @gcd1(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: 'Dependence Analysis' for function 'gcd1'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

; DELIN: 'Dependence Analysis' for function 'gcd1'
; DELIN-LABEL: gcd1
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - none!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -138,15 +121,7 @@ define void @gcd2(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: 'Dependence Analysis' for function 'gcd2'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

; DELIN: 'Dependence Analysis' for function 'gcd2'
; DELIN-LABEL: gcd2
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - none!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -200,15 +175,7 @@ define void @gcd3(i32* %A, i32* %B) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: 'Dependence Analysis' for function 'gcd3'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - flow [<> *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

; DELIN: 'Dependence Analysis' for function 'gcd3'
; DELIN-LABEL: gcd3
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - flow [<> *]!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -260,15 +227,7 @@ define void @gcd4(i32* %A, i32* %B, i64 %M, i64 %N) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: 'Dependence Analysis' for function 'gcd4'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

; DELIN: 'Dependence Analysis' for function 'gcd4'
; DELIN-LABEL: gcd4
; DELIN: da analyze - none!
; DELIN: da analyze - none!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -330,15 +289,7 @@ define void @gcd5(i32* %A, i32* %B, i64 %M, i64 %N) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: 'Dependence Analysis' for function 'gcd5'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - flow [<> *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

; DELIN: 'Dependence Analysis' for function 'gcd5'
; DELIN-LABEL: gcd5
; DELIN: da analyze - none!
; DELIN: da analyze - flow [> *]!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -401,15 +352,7 @@ entry:
%cmp4 = icmp sgt i64 %n, 0
br i1 %cmp4, label %for.cond1.preheader.preheader, label %for.end12

; CHECK: 'Dependence Analysis' for function 'gcd6'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - output [* *]!

; DELIN: 'Dependence Analysis' for function 'gcd6'
; DELIN-LABEL: gcd6
; DELIN: da analyze - none!
; DELIN: da analyze - none!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -481,15 +424,7 @@ entry:
%cmp4 = icmp sgt i32 %n, 0
br i1 %cmp4, label %for.cond1.preheader.preheader, label %for.end15

; CHECK: 'Dependence Analysis' for function 'gcd7'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - flow [* *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - output [* *]!

; DELIN: 'Dependence Analysis' for function 'gcd7'
; DELIN-LABEL: gcd7
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - flow [* *|<]!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -573,17 +508,9 @@ entry:
%cmp4 = icmp sgt i32 %n, 0
br i1 %cmp4, label %for.cond1.preheader.preheader, label %for.end15

; CHECK: 'Dependence Analysis' for function 'gcd8'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - output [* *]!

; DELIN: 'Dependence Analysis' for function 'gcd8'
; DELIN-LABEL: gcd8
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - none!
; DELIN: da analyze - flow [* *|<]!
; DELIN: da analyze - confused!
; DELIN: da analyze - input [* *]!
; DELIN: da analyze - confused!
Expand Down Expand Up @@ -660,15 +587,7 @@ entry:
%cmp4 = icmp eq i32 %n, 0
br i1 %cmp4, label %for.end15, label %for.cond1.preheader.preheader

; CHECK: 'Dependence Analysis' for function 'gcd9'
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - flow [* *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - output [* *]!

; DELIN: 'Dependence Analysis' for function 'gcd9'
; DELIN-LABEL: gcd9
; DELIN: da analyze - output [* *]!
; DELIN: da analyze - flow [* *|<]!
; DELIN: da analyze - confused!
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Analysis/DependenceAnalysis/Invariant.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
; RUN: opt < %s -analyze -basicaa -da | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s

; Test for a bug, which caused an assert when an invalid
; SCEVAddRecExpr is created in addToCoefficient.

; CHECK-LABEL: foo
; CHECK: da analyze - consistent input [S 0]!
; CHECK: da analyze - input [* 0|<]!
; CHECK: da analyze - input [* *|<]!
; CHECK: da analyze - none!

define float @foo(float %g, [40 x float]* %rr) nounwind {
Expand Down
13 changes: 2 additions & 11 deletions llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
; RUN: opt < %s -analyze -basicaa -da -da-delinearize=false | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s -check-prefix=DELIN

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
Expand All @@ -13,15 +12,11 @@ target triple = "x86_64-apple-macosx10.6.0"
; other subscript. DependenceAnalysis before the fix crashed due to this
; mismatch.
define void @i32_subscript([100 x [100 x i32]]* %a, i32* %b) {
; CHECK-LABEL: 'Dependence Analysis' for function 'i32_subscript'
; DELIN-LABEL: 'Dependence Analysis' for function 'i32_subscript'
entry:
br label %for.body

for.body:
; CHECK: da analyze - none!
; CHECK: da analyze - anti [=|<]!
; CHECK: da analyze - none!
; DELIN: da analyze - none!
; DELIN: da analyze - anti [=|<]!
; DELIN: da analyze - none!
Expand Down Expand Up @@ -55,16 +50,12 @@ target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define void @coupled_miv_type_mismatch(i32 %n) #0 {
; CHECK-LABEL: 'Dependence Analysis' for function 'coupled_miv_type_mismatch'
; DELIN-LABEL: 'Dependence Analysis' for function 'coupled_miv_type_mismatch'
entry:
br label %for.cond

; CHECK: da analyze - input [0 *]!
; CHECK: da analyze - anti [1 *]!
; CHECK: da analyze - none!
; DELIN: da analyze - input [0 *]!
; DELIN: da analyze - anti [1 *]!
; DELIN: da analyze - input [* *]!
; DELIN: da analyze - anti [* *|<]!
; DELIN: da analyze - none!
for.cond: ; preds = %for.inc11, %entry
%indvars.iv11 = phi i64 [ %indvars.iv.next12, %for.inc11 ], [ 1, %entry ]
Expand Down
542 changes: 277 additions & 265 deletions llvm/test/Analysis/DependenceAnalysis/Preliminary.ll

Large diffs are not rendered by default.

42 changes: 25 additions & 17 deletions llvm/test/Analysis/DependenceAnalysis/Propagating.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s -analyze -basicaa -da | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s

; ModuleID = 'Propagating.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
Expand All @@ -14,8 +14,9 @@ define void @prop0([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop0
; CHECK: da analyze - none!
; CHECK: da analyze - consistent flow [1 -1]!
; CHECK: da analyze - flow [< >]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -64,10 +65,11 @@ define void @prop1([100 x [100 x i32]]* %A, i32* %B, i32 %n) nounwind uwtable ss
entry:
br label %for.cond1.preheader

; CHECK: da analyze - none!
; CHECK: da analyze - consistent flow [1 1 -1]!
; CHECK-LABEL: prop1
; CHECK: da analyze - output [* * *]!
; CHECK: da analyze - flow [<> <> *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - input [* * *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

Expand Down Expand Up @@ -126,8 +128,9 @@ define void @prop2([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop2
; CHECK: da analyze - consistent output [0 S]!
; CHECK: da analyze - none!
; CHECK: da analyze - flow [> *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -176,10 +179,11 @@ define void @prop3([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK: da analyze - none!
; CHECK: da analyze - none!
; CHECK-LABEL: prop3
; CHECK: da analyze - output [* *]!
; CHECK: da analyze - flow [<> *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - input [* *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

Expand Down Expand Up @@ -227,8 +231,9 @@ define void @prop4([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop4
; CHECK: da analyze - none!
; CHECK: da analyze - consistent flow [2 -3]!
; CHECK: da analyze - flow [< <>]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -279,9 +284,9 @@ define void @prop5([100 x [100 x i32]]* %A, i32* %B, i32 %n) nounwind uwtable ss
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop5
; CHECK: da analyze - none!
; CHECK: da analyze - flow [< -16] splitable!
; CHECK: da analyze - split level = 1, iteration = 11!
; CHECK: da analyze - flow [* *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -333,8 +338,9 @@ define void @prop6([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop6
; CHECK: da analyze - none!
; CHECK: da analyze - flow [=> -2]!
; CHECK: da analyze - flow [=> <>]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -386,9 +392,9 @@ define void @prop7([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop7
; CHECK: da analyze - none!
; CHECK: da analyze - flow [* -38] splitable!
; CHECK: da analyze - split level = 1, iteration = 4!
; CHECK: da analyze - flow [* <>]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -442,8 +448,9 @@ define void @prop8([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop8
; CHECK: da analyze - consistent output [S 0]!
; CHECK: da analyze - flow [p<= 2]!
; CHECK: da analyze - flow [=> <]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -493,8 +500,9 @@ define void @prop9([100 x i32]* %A, i32* %B, i32 %n) nounwind uwtable ssp {
entry:
br label %for.cond1.preheader

; CHECK-LABEL: prop9
; CHECK: da analyze - none!
; CHECK: da analyze - flow [p<= 2]!
; CHECK: da analyze - flow [<= <]!
; CHECK: da analyze - confused!
; CHECK: da analyze - consistent input [S 0]!
; CHECK: da analyze - confused!
Expand Down
26 changes: 13 additions & 13 deletions llvm/test/Analysis/DependenceAnalysis/Separability.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s -analyze -basicaa -da | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s

; ModuleID = 'Separability.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
Expand All @@ -16,10 +16,10 @@ define void @sep0([100 x [100 x i32]]* %A, i32* %B, i32 %n) nounwind uwtable ssp
entry:
br label %for.cond1.preheader

; CHECK: da analyze - output [0 * * S]!
; CHECK: da analyze - flow [-10 * * *]!
; CHECK: da analyze - output [= * * S]!
; CHECK: da analyze - flow [* * * *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [0 * S *]!
; CHECK: da analyze - input [* * S *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

Expand Down Expand Up @@ -91,10 +91,10 @@ define void @sep1([100 x [100 x i32]]* %A, i32* %B, i32 %n) nounwind uwtable ssp
entry:
br label %for.cond1.preheader

; CHECK: da analyze - output [0 * * S]!
; CHECK: da analyze - flow [> * * *]!
; CHECK: da analyze - output [= * * S]!
; CHECK: da analyze - flow [* * * *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [0 * S *]!
; CHECK: da analyze - input [* * S *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

Expand Down Expand Up @@ -165,10 +165,10 @@ define void @sep2([100 x [100 x [100 x i32]]]* %A, i32* %B, i32 %n) nounwind uwt
entry:
br label %for.cond1.preheader

; CHECK: da analyze - consistent output [0 S 0 0]!
; CHECK: da analyze - flow [> * * -10]!
; CHECK: da analyze - output [= S = =]!
; CHECK: da analyze - flow [* * * <>]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [0 * * 0]!
; CHECK: da analyze - input [= * * *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

Expand Down Expand Up @@ -239,10 +239,10 @@ define void @sep3([100 x [100 x [100 x i32]]]* %A, i32* %B, i32 %n) nounwind uwt
entry:
br label %for.cond1.preheader

; CHECK: da analyze - consistent output [0 S 0 0]!
; CHECK: da analyze - flow [> * * *]!
; CHECK: da analyze - output [= S = =]!
; CHECK: da analyze - flow [* * * *|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - input [0 * * 0]!
; CHECK: da analyze - input [= * * *]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Analysis/DependenceAnalysis/StrongSIV.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s -analyze -basicaa -da | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s

; ModuleID = 'StrongSIV.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
Expand Down Expand Up @@ -328,7 +328,7 @@ entry:
br label %for.body

; CHECK: da analyze - none!
; CHECK: da analyze - consistent flow [%n|<]!
; CHECK: da analyze - flow [*|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down
11 changes: 6 additions & 5 deletions llvm/test/Analysis/DependenceAnalysis/SymbolicSIV.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s -analyze -basicaa -da | FileCheck %s
; RUN: opt < %s -analyze -basicaa -da -da-delinearize | FileCheck %s

; ModuleID = 'SymbolicSIV.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
Expand Down Expand Up @@ -291,7 +291,7 @@ entry:

; CHECK: da analyze - none!
; CHECK: da analyze - flow [*|<] splitable!
; CHECK: da analyze - split level = 1, iteration = ((0 smax (-1 + (-1 * %n))) /u 2)!
; CHECK: da analyze - split level = 1, iteration = ((0 smax (-4 + (-4 * %n))) /u 8)!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -334,8 +334,9 @@ entry:
%cmp1 = icmp eq i64 %n, 0
br i1 %cmp1, label %for.end, label %for.body.preheader

; CHECK-LABEL: symbolicsiv6
; CHECK: da analyze - none!
; CHECK: da analyze - none!
; CHECK: da analyze - flow [0|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down Expand Up @@ -382,9 +383,9 @@ define void @symbolicsiv7(i32* %A, i32* %B, i64 %n, i64 %N, i64 %M) nounwind uwt
entry:
%cmp1 = icmp eq i64 %n, 0
br i1 %cmp1, label %for.end, label %for.body.preheader

; CHECK-LABEL: symbolicsiv7
; CHECK: da analyze - none!
; CHECK: da analyze - flow [<>]!
; CHECK: da analyze - flow [0|<]!
; CHECK: da analyze - confused!
; CHECK: da analyze - none!
; CHECK: da analyze - confused!
Expand Down
44 changes: 6 additions & 38 deletions llvm/test/Transforms/LoopInterchange/call-instructions.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -20,6 +20,8 @@ declare void @bar(i64 %a) readnone
;; }
;; }

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_01(i32 %k, i32 %N) {
entry:
%cmp21 = icmp sgt i32 %N, 0
Expand Down Expand Up @@ -65,24 +67,6 @@ exit:
ret void
}

; CHECK-LABEL: @interchange_01
; CHECK: for1.ph:
; CHECK: br label %for1.header

; CHECK: for1.header:
; CHECK-NEXT: %indvars.iv23 = phi i64 [ 0, %for1.ph ], [ %indvars.iv.next24, %for1.inc10 ]
; CHECK-NEXT: br i1 %cmp219, label %for2.ph, label %for1.inc10

; CHECK: for2:
; CHECK: br i1 %exitcond, label %for2.loopexit, label %for2

; CHECK: for1.inc10:
; CHECK: br i1 %exitcond26, label %for1.loopexit, label %for1.header

; CHECK: for1.loopexit:
; CHECK-NEXT: br label %exit


;;--------------------------------------Test case 02------------------------------------
;; Safe to interchange, because the called function `bar` is marked as readnone,
;; so it cannot introduce dependences.
Expand All @@ -94,6 +78,8 @@ exit:
;; }
;; }

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_02(i32 %k, i32 %N) {
entry:
%cmp21 = icmp sgt i32 %N, 0
Expand Down Expand Up @@ -138,21 +124,3 @@ for1.loopexit:
exit:
ret void
}

; CHECK-LABEL: @interchange_02
; CHECK: for1.header:
; CHECK-NEXT: %indvars.iv23 = phi i64 [ 0, %for1.ph ], [ %indvars.iv.next24, %for1.inc10 ]
; CHECK-NEXT: br i1 %cmp219, label %for2.split1, label %for1.loopexit

; CHECK: for2.split1:
; CHECK: br label %for2.loopexit

; CHECK: for2.split:
; CHECK-NEXT: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: br i1 %exitcond, label %for1.loopexit, label %for2

; CHECK: for2.loopexit:
; CHECK-NEXT: br label %for1.inc10

; CHECK: for1.inc10:
; CHECK: br i1 %exitcond26, label %for2.split, label %for1.header
14 changes: 4 additions & 10 deletions llvm/test/Transforms/LoopInterchange/current-limitations-lcssa.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -13,6 +13,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(gj=1;gj<M;gj++)
;; A[gj][gi] = A[gj - 1][gi] + C[gj][gi];

; CHECK: PHI Nodes in loop nest exit is not handled for now since on failure all loops branch to loop nest exit.

@gi = common global i32 0
@gj = common global i32 0

Expand Down Expand Up @@ -66,11 +68,3 @@ for.cond.for.end16_crit_edge:
for.end16:
ret void
}

; CHECK-LABEL: @interchange_07
; CHECK: for.body3: ; preds = %for.body3.preheader, %for.body3
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 1, %for.body3.preheader ]
; CHECK: %5 = add nsw i64 %indvars.iv, -1
; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %5, i64 %indvars.iv25
; CHECK: %6 = load i32, i32* %arrayidx5
; CHECK: %arrayidx9 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @C, i64 0, i64 %indvars.iv, i64 %indvars.iv25
13 changes: 4 additions & 9 deletions llvm/test/Transforms/LoopInterchange/currentLimitation.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; These are test that fail to interchange due to current limitation. This will go off once we extend the loop interchange pass.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -14,6 +14,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int j=1;j<N-1;j++)
;; A[j+1][i+1] = A[j+1][i+1] + k;

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_01(i32 %k, i32 %N) {
entry:
%sub = add nsw i32 %N, -1
Expand Down Expand Up @@ -49,10 +51,3 @@ define void @interchange_01(i32 %k, i32 %N) {
for.end17:
ret void
}
;; Inner loop not split so it is not interchanged.
; CHECK-LABEL: @interchange_01
; CHECK: for.body4:
; CHECK-NEXT: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body4 ], [ 1, %for.body4.preheader ]
; CHECK-NEXT: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK-NEXT: %arrayidx7 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next29

59 changes: 8 additions & 51 deletions llvm/test/Transforms/LoopInterchange/interchange-flow-dep-outer.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -20,6 +20,12 @@ target triple = "x86_64-unknown-linux-gnu"
;; fn2(T[k]);
;; }

; CHECK: Processing Inner Loop Id = 2 and OuterLoopId = 1
; CHECK: Loops interchanged.

; CHECK: Processing Inner Loop Id = 1 and OuterLoopId = 0
; CHECK: Not interchanging loops. Cannot prove legality.

@T = internal global [100 x double] zeroinitializer, align 4
@Arr = internal global [1000 x [1000 x i32]] zeroinitializer, align 4

Expand Down Expand Up @@ -67,52 +73,3 @@ for.body9: ; preds = %for.body9, %for.con

declare double @fn1() readnone
declare void @fn2(double) readnone


;; After interchange %indvars.iv (j) should increment as the middle loop.
;; After interchange %indvars.iv42 (i) should increment with the inner most loop.

; CHECK-LABEL: @interchange_09

; CHECK: for.body:
; CHECK: %indvars.iv45 = phi i64 [ %indvars.iv.next46, %for.cond.cleanup4 ], [ 0, %for.body.preheader ]
; CHECK: %call = call double @fn1()
; CHECK: %arrayidx = getelementptr inbounds [100 x double], [100 x double]* @T, i64 0, i64 %indvars.iv45
; CHECK: store double %call, double* %arrayidx, align 8
; CHECK: br label %for.body9.preheader

; CHECK: for.cond6.preheader.preheader:
; CHECK: br label %for.cond6.preheader

; CHECK: for.cond6.preheader:
; CHECK: %indvars.iv42 = phi i64 [ %indvars.iv.next43, %for.cond.cleanup8 ], [ 0, %for.cond6.preheader.preheader ]
; CHECK: br label %for.body9.split1

; CHECK: for.body9.preheader:
; CHECK: br label %for.body9

; CHECK: for.cond.cleanup4:
; CHECK: %tmp = load double, double* %arrayidx, align 8
; CHECK: call void @fn2(double %tmp)
; CHECK: %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
; CHECK: %exitcond47 = icmp ne i64 %indvars.iv.next46, 100
; CHECK: br i1 %exitcond47, label %for.body, label %for.cond.cleanup

; CHECK: for.cond.cleanup8:
; CHECK: %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
; CHECK: %exitcond44 = icmp ne i64 %indvars.iv.next43, 1000
; CHECK: br i1 %exitcond44, label %for.cond6.preheader, label %for.body9.split

; CHECK: for.body9:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body9.split ], [ 1, %for.body9.preheader ]
; CHECK: br label %for.cond6.preheader.preheader

; CHECK: for.body9.split1:
; CHECK: %arrayidx13 = getelementptr inbounds [1000 x [1000 x i32]], [1000 x [1000 x i32]]* @Arr, i64 0, i64 %indvars.iv, i64 %indvars.iv42
; CHECK: store i32 %add, i32* %arrayidx13, align 4
; CHECK: br label %for.cond.cleanup8

; CHECK: for.body9.split:
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, 1000
; CHECK: br i1 %exitcond, label %for.body9, label %for.cond.cleanup4
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
; RUN: opt < %s -basicaa -da-delinearize -loop-interchange -verify-dom-info -S -pass-remarks=loop-interchange 2>&1 | FileCheck %s

@A10 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16

;; Test to make sure we can handle zext intructions introduced by
;; Test to make sure we can handle zext instructions introduced by
;; IndVarSimplify.
;;
;; for (int i = 0; i < 2; ++i)
;; for(int j = 0; j < n; ++j) {
;; A[j][i] = i;
;; }

; CHECK: Loop interchanged with enclosing loop.

@A11 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16

define void @interchange_11(i32 %n) {
Expand All @@ -30,9 +32,11 @@ for.cond.cleanup: ; preds = %for.cond.loopexit

for.body4: ; preds = %for.body4, %for.cond1.preheader
%indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body4 ]
%arrayidx6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv26
%tmp = trunc i64 %indvars.iv26 to i32
store i32 %tmp, i32* %arrayidx6, align 4
; The store below does not appear in the C snippet above.
; With two stores in the loop there may be WAW dependences, and interchange is illegal.
; %arrayidx6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv26
; %tmp = trunc i64 %indvars.iv26 to i32
; store i32 %tmp, i32* %arrayidx6, align 4
%arrayidx10 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv.next27
%tmp1 = trunc i64 %indvars.iv to i32
store i32 %tmp1, i32* %arrayidx10, align 4
Expand All @@ -41,40 +45,3 @@ for.body4: ; preds = %for.body4, %for.con
%exitcond = icmp ne i64 %indvars.iv.next, %n.wide
br i1 %exitcond, label %for.body4, label %for.cond.loopexit
}

; CHECK-LABEL: @interchange_11
; CHECK: entry:
; CHECK: br label %for.body4.preheader

; CHECK: for.cond1.preheader.preheader:
; CHECK: br label %for.cond1.preheader

; CHECK: for.cond.loopexit:
; CHECK: %exitcond28 = icmp ne i64 %indvars.iv.next27, 2
; CHECK: br i1 %exitcond28, label %for.cond1.preheader, label %for.body4.split

; CHECK: for.cond1.preheader:
; CHECK: %indvars.iv26 = phi i64 [ %indvars.iv.next27, %for.cond.loopexit ], [ 0, %for.cond1.preheader.preheader ]
; CHECK: %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
; CHECK: br label %for.body4.split1

; CHECK: for.body4.preheader:
; CHECK: br label %for.body4

; CHECK: for.cond.cleanup:
; CHECK: ret void

; CHECK: for.body4:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body4.split ], [ 0, %for.body4.preheader ]
; CHECK: br label %for.cond1.preheader.preheader

; CHECK: for.body4.split1:
; CHECK: %arrayidx6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv26
; CHECK: %tmp = trunc i64 %indvars.iv26 to i32
; CHECK: store i32 %tmp, i32* %arrayidx6, align 4
; CHECK: br label %for.cond.loopexit

; CHECK: for.body4.split:
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, %n.wide
; CHECK: br i1 %exitcond, label %for.body4, label %for.cond.cleanup
40 changes: 0 additions & 40 deletions llvm/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll

This file was deleted.

20 changes: 3 additions & 17 deletions llvm/test/Transforms/LoopInterchange/interchange-no-deps.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
; RUN: opt < %s -loop-interchange -simplifycfg -S | FileCheck %s
; RUN: opt < %s -loop-interchange -simplifycfg -S -pass-remarks=loop-interchange 2>&1 | FileCheck %s
; CHECK: Loop interchanged with enclosing loop.

; 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
Expand All @@ -26,19 +28,3 @@ for.cond.cleanup3: ; preds = %for.body4
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
32 changes: 4 additions & 28 deletions llvm/test/Transforms/LoopInterchange/interchange-not-profitable.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -12,6 +12,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int j=0;j<100;j++)
;; A[i][j] = A[i][j]+k;

; CHECK: Interchanging loops not profitable.

define void @interchange_03(i32 %k) {
entry:
br label %for.cond1.preheader
Expand All @@ -38,29 +40,3 @@ for.inc10:
for.end12:
ret void
}

; CHECK-LABEL: @interchange_03
; CHECK: entry:
; CHECK: br label %for.cond1.preheader.preheader
; CHECK: for.cond1.preheader.preheader: ; preds = %entry
; CHECK: br label %for.cond1.preheader
; CHECK: for.cond1.preheader: ; preds = %for.cond1.preheader.preheader, %for.inc10
; CHECK: %indvars.iv21 = phi i64 [ %indvars.iv.next22, %for.inc10 ], [ 0, %for.cond1.preheader.preheader ]
; CHECK: br label %for.body3.preheader
; CHECK: for.body3.preheader: ; preds = %for.cond1.preheader
; CHECK: br label %for.body3
; CHECK: for.body3: ; preds = %for.body3.preheader, %for.body3
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 0, %for.body3.preheader ]
; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv21, i64 %indvars.iv
; CHECK: %0 = load i32, i32* %arrayidx5
; CHECK: %add = add nsw i32 %0, %k
; CHECK: store i32 %add, i32* %arrayidx5
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %exitcond = icmp eq i64 %indvars.iv.next, 100
; CHECK: br i1 %exitcond, label %for.inc10, label %for.body3
; CHECK: for.inc10: ; preds = %for.body3
; CHECK: %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
; CHECK: %exitcond23 = icmp eq i64 %indvars.iv.next22, 100
; CHECK: br i1 %exitcond23, label %for.end12, label %for.cond1.preheader
; CHECK: for.end12: ; preds = %for.inc10
; CHECK: ret void
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -14,6 +14,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; A[j][i+1] = j;
;; }

; CHECK: Not interchanging loops. Cannot prove legality.

@A10 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16

define void @interchange_10() {
Expand Down Expand Up @@ -44,43 +46,3 @@ for.body4: ; preds = %for.body4, %for.con
%exitcond = icmp ne i64 %indvars.iv.next, 3
br i1 %exitcond, label %for.body4, label %for.cond.loopexit
}

; CHECK-LABEL: @interchange_10
; CHECK: entry:
; CHECK: br label %for.body4.preheader

; CHECK: for.cond1.preheader.preheader:
; CHECK: br label %for.cond1.preheader

; CHECK: for.cond.loopexit:
; CHECK: %exitcond28 = icmp ne i64 %indvars.iv.next27, 2
; CHECK: br i1 %exitcond28, label %for.cond1.preheader, label %for.body4.split

; CHECK: for.cond1.preheader:
; CHECK: %indvars.iv26 = phi i64 [ %indvars.iv.next27, %for.cond.loopexit ], [ 0, %for.cond1.preheader.preheader ]
; CHECK: %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
; CHECK: br label %for.body4.split1

; CHECK: for.body4.preheader:
; CHECK: br label %for.body4

; CHECK: for.cond.cleanup:
; CHECK: ret void

; CHECK: for.body4:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body4.split ], [ 0, %for.body4.preheader ]
; CHECK: br label %for.cond1.preheader.preheader

; CHECK: for.body4.split1:
; CHECK: %arrayidx6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv26
; CHECK: %tmp = trunc i64 %indvars.iv26 to i32
; CHECK: store i32 %tmp, i32* %arrayidx6, align 4
; CHECK: %arrayidx10 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv.next27
; CHECK: %tmp1 = trunc i64 %indvars.iv to i32
; CHECK: store i32 %tmp1, i32* %arrayidx10, align 4
; CHECK: br label %for.cond.loopexit

; CHECK: for.body4.split:
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %exitcond = icmp ne i64 %indvars.iv.next, 3
; CHECK: br i1 %exitcond, label %for.body4, label %for.cond.cleanup
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -pass-remarks=loop-interchange 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -11,6 +10,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int j=100;j>=0;j--)
;; A[j][i] = A[j][i]+k;

; CHECK: Loop interchanged with enclosing loop.

define void @interchange_02(i32 %k) {
entry:
br label %for.cond1.preheader
Expand All @@ -37,33 +38,3 @@ for.inc10:
for.end11:
ret void
}

; CHECK-LABEL: @interchange_02
; CHECK: entry:
; CHECK: br label %for.body3.preheader
; CHECK: for.cond1.preheader.preheader:
; CHECK: br label %for.cond1.preheader
; CHECK: for.cond1.preheader:
; CHECK: %indvars.iv19 = phi i64 [ %indvars.iv.next20, %for.inc10 ], [ 0, %for.cond1.preheader.preheader ]
; CHECK: br label %for.body3.split1
; CHECK: for.body3.preheader:
; CHECK: br label %for.body3
; CHECK: for.body3:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3.split ], [ 100, %for.body3.preheader ]
; CHECK: br label %for.cond1.preheader.preheader
; CHECK: for.body3.split1: ; preds = %for.cond1.preheader
; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv19
; CHECK: %0 = load i32, i32* %arrayidx5
; CHECK: %add = add nsw i32 %0, %k
; CHECK: store i32 %add, i32* %arrayidx5
; CHECK: br label %for.inc10
; CHECK: for.body3.split:
; CHECK: %indvars.iv.next = add nsw i64 %indvars.iv, -1
; CHECK: %cmp2 = icmp sgt i64 %indvars.iv, 0
; CHECK: br i1 %cmp2, label %for.body3, label %for.end11
; CHECK: for.inc10:
; CHECK: %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
; CHECK: %exitcond = icmp eq i64 %indvars.iv.next20, 100
; CHECK: br i1 %exitcond, label %for.body3.split, label %for.cond1.preheader
; CHECK: for.end11:
; CHECK: ret void
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -11,6 +11,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int j=1;j<N;j++)
;; A[j][i] = A[j][i]+k;

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_01(i32 %k, i32 %N) {
entry:
%cmp21 = icmp sgt i32 %N, 0
Expand Down Expand Up @@ -45,42 +47,3 @@ for.inc10:
for.end12:
ret void
}

; CHECK-LABEL: @interchange_01
; CHECK: entry:
; CHECK: %cmp21 = icmp sgt i32 %N, 0
; CHECK: br i1 %cmp21, label %for.body3.preheader, label %for.end12
; CHECK: for.cond1.preheader.lr.ph:
; CHECK: br label %for.cond1.preheader
; CHECK: for.cond1.preheader:
; CHECK: %indvars.iv23 = phi i64 [ 0, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next24, %for.inc10 ]
; CHECK: br i1 %cmp219, label %for.body3.split1, label %for.end12.loopexit
; CHECK: for.body3.preheader:
; CHECK: %cmp219 = icmp sgt i32 %N, 1
; CHECK: %0 = add i32 %N, -1
; CHECK: br label %for.body3
; CHECK: for.body3:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3.split ], [ 1, %for.body3.preheader ]
; CHECK: br label %for.cond1.preheader.lr.ph
; CHECK: for.body3.split1:
; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
; CHECK: %1 = load i32, i32* %arrayidx5
; CHECK: %add = add nsw i32 %1, %k
; CHECK: store i32 %add, i32* %arrayidx5
; CHECK: br label %for.inc10.loopexit
; CHECK: for.body3.split:
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %lftr.wideiv = trunc i64 %indvars.iv to i32
; CHECK: %exitcond = icmp eq i32 %lftr.wideiv, %0
; CHECK: br i1 %exitcond, label %for.end12.loopexit, label %for.body3
; CHECK: for.inc10.loopexit:
; CHECK: br label %for.inc10
; CHECK: for.inc10:
; CHECK: %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
; CHECK: %lftr.wideiv25 = trunc i64 %indvars.iv23 to i32
; CHECK: %exitcond26 = icmp eq i32 %lftr.wideiv25, %0
; CHECK: br i1 %exitcond26, label %for.body3.split, label %for.cond1.preheader
; CHECK: for.end12.loopexit:
; CHECK: br label %for.end12
; CHECK: for.end12:
; CHECK: ret void
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ for.end19:

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: InterchangeNotProfitable
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: test01
; CHECK-NEXT: Args:
; CHECK-NEXT: - String: 'Interchanging loops is too costly (cost='
; CHECK-NEXT: - Cost: '2'
; CHECK-NEXT: - String: ', threshold='
; CHECK-NEXT: - Threshold: '0'
; CHECK-NEXT: - String: ') and it does not improve parallelism.'
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.
; CHECK-NEXT: ...

;;--------------------------------------Test case 02------------------------------------
Expand Down Expand Up @@ -110,10 +106,10 @@ define void @test02(i32 %k, i32 %N) {

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: UnsupportedInsBetweenInduction
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: test02
; CHECK-NEXT: Args:
; CHECK-NEXT: - String: Found unsupported instruction between induction variable increment and branch.
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.
; CHECK-NEXT: ...

;;-----------------------------------Test case 03-------------------------------
Expand Down Expand Up @@ -156,12 +152,12 @@ for.body4: ; preds = %for.body4, %for.con
br i1 %exitcond, label %for.body4, label %for.cond.loopexit
}

; CHECK: --- !Passed
; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: Interchanged
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: test03
; CHECK-NEXT: Args:
; CHECK-NEXT: - String: Loop interchanged with enclosing loop.
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.
; CHECK-NEXT: ...

;;--------------------------------------Test case 04-------------------------------------
Expand Down Expand Up @@ -213,8 +209,8 @@ for.end17:

; CHECK: --- !Missed
; CHECK-NEXT: Pass: loop-interchange
; CHECK-NEXT: Name: NotTightlyNested
; CHECK-NEXT: Name: Dependence
; CHECK-NEXT: Function: test04
; CHECK-NEXT: Args:
; CHECK-NEXT: - String: Cannot interchange loops because they are not tightly nested.
; CHECK-NEXT: - String: Cannot interchange loops due to dependences.
; CHECK-NEXT: ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -12,6 +12,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int i=0;i<99;i++)
;; A[j][i+1] = A[j+1][i]+k;

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_04(i32 %k){
entry:
br label %for.cond1.preheader
Expand Down Expand Up @@ -39,26 +41,3 @@ for.inc12:
for.end14:
ret void
}

; CHECK-LABEL: @interchange_04
; CHECK: entry:
; CHECK: br label %for.cond1.preheader
; CHECK: for.cond1.preheader: ; preds = %for.inc12, %entry
; CHECK: %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for.inc12 ]
; CHECK: %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
; CHECK: br label %for.body3
; CHECK: for.body3: ; preds = %for.body3, %for.cond1.preheader
; CHECK: %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body3 ]
; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv.next24, i64 %indvars.iv
; CHECK: %0 = load i32, i32* %arrayidx5
; CHECK: %add6 = add nsw i32 %0, %k
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %arrayidx11 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv23, i64 %indvars.iv.next
; CHECK: store i32 %add6, i32* %arrayidx11
; CHECK: %exitcond = icmp eq i64 %indvars.iv.next, 99
; CHECK: br i1 %exitcond, label %for.inc12, label %for.body3
; CHECK: for.inc12: ; preds = %for.body3
; CHECK: %exitcond25 = icmp eq i64 %indvars.iv.next24, 99
; CHECK: br i1 %exitcond25, label %for.end14, label %for.cond1.preheader
; CHECK: for.end14: ; preds = %for.inc12
; CHECK: ret void
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -12,6 +12,12 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int k=0;k<100;k++)
;; D[i][k][j] = D[i][k][j]+t;

; CHECK: Processing Inner Loop Id = 2 and OuterLoopId = 1
; CHECK: Loops interchanged.

; CHECK: Processing Inner Loop Id = 1 and OuterLoopId = 0
; CHECK: Interchanging loops not profitable.

define void @interchange_08(i32 %t){
entry:
br label %for.cond1.preheader
Expand Down Expand Up @@ -47,41 +53,3 @@ for.inc15: ; preds = %for.inc12
for.end17: ; preds = %for.inc15
ret void
}
; CHECK-LABEL: @interchange_08
; CHECK: entry:
; CHECK: br label %for.cond1.preheader.preheader
; CHECK: for.cond1.preheader.preheader: ; preds = %entry
; CHECK: br label %for.cond1.preheader
; CHECK: for.cond1.preheader: ; preds = %for.cond1.preheader.preheader, %for.inc15
; CHECK: %i.028 = phi i32 [ %inc16, %for.inc15 ], [ 0, %for.cond1.preheader.preheader ]
; CHECK: br label %for.body6.preheader
; CHECK: for.cond4.preheader.preheader: ; preds = %for.body6
; CHECK: br label %for.cond4.preheader
; CHECK: for.cond4.preheader: ; preds = %for.cond4.preheader.preheader, %for.inc12
; CHECK: %j.027 = phi i32 [ %inc13, %for.inc12 ], [ 0, %for.cond4.preheader.preheader ]
; CHECK: br label %for.body6.split1
; CHECK: for.body6.preheader: ; preds = %for.cond1.preheader
; CHECK: br label %for.body6
; CHECK: for.body6: ; preds = %for.body6.preheader, %for.body6.split
; CHECK: %k.026 = phi i32 [ %inc, %for.body6.split ], [ 0, %for.body6.preheader ]
; CHECK: br label %for.cond4.preheader.preheader
; CHECK: for.body6.split1: ; preds = %for.cond4.preheader
; CHECK: %arrayidx8 = getelementptr inbounds [100 x [100 x [100 x i32]]], [100 x [100 x [100 x i32]]]* @D, i32 0, i32 %i.028, i32 %k.026, i32 %j.027
; CHECK: %0 = load i32, i32* %arrayidx8
; CHECK: %add = add nsw i32 %0, %t
; CHECK: store i32 %add, i32* %arrayidx8
; CHECK: br label %for.inc12
; CHECK: for.body6.split: ; preds = %for.inc12
; CHECK: %inc = add nuw nsw i32 %k.026, 1
; CHECK: %exitcond = icmp eq i32 %inc, 100
; CHECK: br i1 %exitcond, label %for.inc15, label %for.body6
; CHECK: for.inc12: ; preds = %for.body6.split1
; CHECK: %inc13 = add nuw nsw i32 %j.027, 1
; CHECK: %exitcond29 = icmp eq i32 %inc13, 100
; CHECK: br i1 %exitcond29, label %for.body6.split, label %for.cond4.preheader
; CHECK: for.inc15: ; preds = %for.body6.split
; CHECK: %inc16 = add nuw nsw i32 %i.028, 1
; CHECK: %exitcond30 = icmp eq i32 %inc16, 100
; CHECK: br i1 %exitcond30, label %for.end17, label %for.cond1.preheader
; CHECK: for.end17: ; preds = %for.inc15
; CHECK: ret void
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -S | FileCheck %s
;; We test the complete .ll for adjustment in outer loop header/latch and inner loop header/latch.
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -S -debug 2>&1 | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Expand All @@ -16,6 +16,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; A[j][i] = A[j][i]+B[j];
;; }

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_05(i32 %k, i32 %N){
entry:
%cmp30 = icmp sgt i32 %N, 0
Expand Down Expand Up @@ -55,44 +57,6 @@ for.end17:
ret void
}

; CHECK-LABEL: @interchange_05
; CHECK: entry:
; CHECK: %cmp30 = icmp sgt i32 %N, 0
; CHECK: br i1 %cmp30, label %for.body.lr.ph, label %for.end17
; CHECK: for.body.lr.ph:
; CHECK: %0 = add i32 %N, -1
; CHECK: %1 = zext i32 %k to i64
; CHECK: br label %for.body
; CHECK: for.body:
; CHECK: %indvars.iv32 = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next33, %for.inc15 ]
; CHECK: %2 = add nsw i64 %indvars.iv32, %1
; CHECK: %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* @B, i64 0, i64 %indvars.iv32
; CHECK: %3 = trunc i64 %2 to i32
; CHECK: store i32 %3, i32* %arrayidx
; CHECK: br label %for.body3.preheader
; CHECK: for.body3.preheader:
; CHECK: br label %for.body3
; CHECK: for.body3:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 0, %for.body3.preheader ]
; CHECK: %arrayidx7 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv32, i64 %indvars.iv
; CHECK: %4 = load i32, i32* %arrayidx7
; CHECK: %add10 = add nsw i32 %3, %4
; CHECK: store i32 %add10, i32* %arrayidx7
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
; CHECK: %lftr.wideiv = trunc i64 %indvars.iv to i32
; CHECK: %exitcond = icmp eq i32 %lftr.wideiv, %0
; CHECK: br i1 %exitcond, label %for.inc15, label %for.body3
; CHECK: for.inc15:
; CHECK: %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
; CHECK: %lftr.wideiv35 = trunc i64 %indvars.iv32 to i32
; CHECK: %exitcond36 = icmp eq i32 %lftr.wideiv35, %0
; CHECK: br i1 %exitcond36, label %for.end17.loopexit, label %for.body
; CHECK: for.end17.loopexit:
; CHECK: br label %for.end17
; CHECK: for.end17:
; CHECK: ret void


declare void @foo(...) readnone

;; Loops not tightly nested are not interchanged
Expand All @@ -102,6 +66,8 @@ declare void @foo(...) readnone
;; A[j][i] = A[j][i]+k;
;; }

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_06(i32 %k, i32 %N) {
entry:
%cmp22 = icmp sgt i32 %N, 0
Expand Down Expand Up @@ -136,8 +102,3 @@ for.inc10:
for.end12:
ret void
}
;; Here we are checking if the inner phi is not split then we have not interchanged.
; CHECK-LABEL: @interchange_06
; CHECK: phi i64 [ %indvars.iv.next, %for.body3 ], [ 2, %for.body3.preheader ]
; CHECK-NEXT: getelementptr
; CHECK-NEXT: %1 = load
32 changes: 4 additions & 28 deletions llvm/test/Transforms/LoopInterchange/phi-ordering.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
; RUN: opt < %s -loop-interchange -verify-dom-info -S | FileCheck %s
; REQUIRES: asserts
; RUN: opt < %s -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s
;; Checks the order of the inner phi nodes does not cause havoc.
;; The inner loop has a reduction into c. The IV is not the first phi.

; CHECK: Not interchanging loops. Cannot prove legality.

target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv8--linux-gnueabihf"

Expand Down Expand Up @@ -61,30 +64,3 @@ for.end21.loopexit: ; preds = %for.inc19
for.end21: ; preds = %for.end21.loopexit, %entry
ret void
}


; CHECK-LABEL: test
; CHECK: entry:
; CHECK: br i1 %cmp45, label %for.body6.preheader, label %for.end21
; CHECK: for.body3.lr.ph.preheader:
; CHECK: br label %for.body3.lr.ph
; CHECK: for.body3.lr.ph:
; CHECK: br label %for.body6.lr.ph.preheader
; CHECK: for.body6.lr.ph.preheader:
; CHECK: br label %for.body6.lr.ph
; CHECK: for.body6.lr.ph:
; CHECK: br label %for.body6.split1
; CHECK: for.body6.preheader:
; CHECK: br label %for.body6
; CHECK: for.body6:
; CHECK: br label %for.body3.lr.ph.preheader
; CHECK: for.body6.split1:
; CHECK: br label %for.inc16
; CHECK: for.body6.split:
; CHECK: add nuw nsw i32 %k.040, 1
; CHECK: br i1 %exitcond, label %for.end21.loopexit, label %for.body6
; CHECK: for.inc16:
; CHECK: br i1 %exitcond47, label %for.inc19, label %for.body6.lr.ph
; CHECK: for.inc19:
; CHECK: br i1 %exitcond48, label %for.body6.split, label %for.body3.lr.ph
; CHECK: for.end21:
72 changes: 8 additions & 64 deletions llvm/test/Transforms/LoopInterchange/profitability.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s
;; We test profitability model in these test cases.

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
Expand All @@ -13,6 +14,8 @@ target triple = "x86_64-unknown-linux-gnu"
;; for(int j=1;j<N;j++)
;; A[j][i] = A[j - 1][i] + B[j][i];

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_01(i32 %N) {
entry:
%cmp27 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -50,30 +53,6 @@ for.inc14:
for.end16:
ret void
}
;; Here we are checking partial .ll to check if loop are interchanged.
; CHECK-LABEL: @interchange_01
; CHECK: for.body3.preheader: ; preds = %for.inc14, %for.cond1.preheader.lr.ph
; CHECK: %indvars.iv30 = phi i64 [ 1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next31, %for.inc14 ]
; CHECK: br label %for.body3.split2

; CHECK: for.body3.preheader1: ; preds = %entry
; CHECK: br label %for.body3

; CHECK: for.body3: ; preds = %for.body3.preheader1, %for.body3.split
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3.split ], [ 1, %for.body3.preheader1 ]
; CHECK: br label %for.cond1.preheader.lr.ph

; CHECK: for.body3.split2: ; preds = %for.body3.preheader
; CHECK: %1 = add nsw i64 %indvars.iv, -1
; CHECK: %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %1, i64 %indvars.iv30
; CHECK: %2 = load i32, i32* %arrayidx5
; CHECK: %arrayidx9 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @B, i64 0, i64 %indvars.iv, i64 %indvars.iv30
; CHECK: %3 = load i32, i32* %arrayidx9
; CHECK: %add = add nsw i32 %3, %2
; CHECK: %arrayidx13 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv, i64 %indvars.iv30
; CHECK: store i32 %add, i32* %arrayidx13
; CHECK: br label %for.inc14


;; ---------------------------------------Test case 02---------------------------------
;; Check loop interchange profitability model.
Expand All @@ -83,6 +62,8 @@ for.end16:
;; for(int j=1;j<N;j++)
;; A[j-1][i-1] = A[j - 1][i-1] + B[j-1][i-1];

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_02(i32 %N) {
entry:
%cmp32 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -120,37 +101,15 @@ for.inc19:
for.end21:
ret void
}
; CHECK-LABEL: @interchange_02
; CHECK: for.body3.lr.ph: ; preds = %for.inc19, %for.cond1.preheader.lr.ph
; CHECK: %indvars.iv35 = phi i64 [ 1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next36, %for.inc19 ]
; CHECK: %0 = add nsw i64 %indvars.iv35, -1
; CHECK: br label %for.body3.split1

; CHECK: for.body3.preheader: ; preds = %entry
; CHECK: %1 = add i32 %N, -1
; CHECK: br label %for.body3

; CHECK: for.body3: ; preds = %for.body3.preheader, %for.body3.split
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3.split ], [ 1, %for.body3.preheader ]
; CHECK: br label %for.cond1.preheader.lr.ph

; CHECK: for.body3.split1: ; preds = %for.body3.lr.ph
; CHECK: %2 = add nsw i64 %indvars.iv, -1
; CHECK: %arrayidx6 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %2, i64 %0
; CHECK: %3 = load i32, i32* %arrayidx6
; CHECK: %arrayidx12 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @B, i64 0, i64 %2, i64 %0
; CHECK: %4 = load i32, i32* %arrayidx12
; CHECK: %add = add nsw i32 %4, %3
; CHECK: store i32 %add, i32* %arrayidx6
; CHECK: br label %for.inc19


;;---------------------------------------Test case 03---------------------------------
;; Loops interchange is not profitable.
;; for(int i=1;i<N;i++)
;; for(int j=1;j<N;j++)
;; A[i-1][j-1] = A[i - 1][j-1] + B[i][j];

; CHECK: Not interchanging loops. Cannot prove legality.

define void @interchange_03(i32 %N){
entry:
%cmp31 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -188,18 +147,3 @@ for.inc17:
for.end19:
ret void
}

; CHECK-LABEL: @interchange_03
; CHECK: for.body3.lr.ph:
; CHECK: %indvars.iv34 = phi i64 [ 1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next35, %for.inc17 ]
; CHECK: %1 = add nsw i64 %indvars.iv34, -1
; CHECK: br label %for.body3.preheader
; CHECK: for.body3.preheader:
; CHECK: br label %for.body3
; CHECK: for.body3:
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3 ], [ 1, %for.body3.preheader ]
; CHECK: %2 = add nsw i64 %indvars.iv, -1
; CHECK: %arrayidx6 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %1, i64 %2
; CHECK: %3 = load i32, i32* %arrayidx6
; CHECK: %arrayidx10 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @B, i64 0, i64 %indvars.iv34, i64 %indvars.iv
; CHECK: %4 = load i32, i32* %arrayidx10
47 changes: 17 additions & 30 deletions llvm/test/Transforms/LoopInterchange/reductions.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S | FileCheck %s
; REQUIRES: asserts
; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -S -debug 2>&1 | FileCheck %s

@A = common global [500 x [500 x i32]] zeroinitializer
@X = common global i32 0
Expand All @@ -9,6 +10,9 @@
;; for( int j=1;j<N;j++)
;; X+=A[j][i];

;; Loop is interchanged check that the phi nodes are split and the promoted value is used instead of the reduction phi.
; CHECK: Loops interchanged.

define void @reduction_01(i32 %N) {
entry:
%cmp16 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -41,14 +45,6 @@ for.end8: ; preds = %for.cond1.for.inc6_
ret void
}

;; Loop is interchanged check that the phi nodes are split and the promoted value is used instead of the reduction phi.
; CHECK-LABEL: @reduction_01
; CHECK: for.body3: ; preds = %for.body3.preheader, %for.body3.split
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body3.split ], [ 1, %for.body3.preheader ]
; CHECK: br label %for.body3.lr.ph.preheader
; CHECK: %add = add nsw i32 %X.promoted


;; Test for more than 1 reductions inside a loop.
;; for( int i=1;i<N;i++)
;; for( int j=1;j<N;j++)
Expand All @@ -57,6 +53,9 @@ for.end8: ; preds = %for.cond1.for.inc6_
;; Y+=B[k][i];
;; }

;; Loop is interchanged check that the phi nodes are split and the promoted value is used instead of the reduction phi.
; CHECK: Loops interchanged.

define void @reduction_02(i32 %N) {
entry:
%cmp34 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -105,14 +104,6 @@ for.end19: ; preds = %for.inc17, %entry
ret void
}

;; Loop is interchanged check that the phi nodes are split and the promoted value is used instead of the reduction phi.
; CHECK-LABEL: @reduction_02
; CHECK: for.body6: ; preds = %for.body6.preheader, %for.body6.split
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body6.split ], [ 1, %for.body6.preheader ]
; CHECK: br label %for.cond4.preheader.preheader.preheader
; CHECK: %add13 = add nsw i32 %Y.promoted


;; Not tightly nested. Do not interchange.
;; for( int i=1;i<N;i++)
;; for( int j=1;j<N;j++) {
Expand All @@ -121,6 +112,11 @@ for.end19: ; preds = %for.inc17, %entry
;; }
;; Y+=B[j][i];
;; }

;; Not tightly nested. Do not interchange.
;; Not interchanged hence the phi's in the inner loop will not be split. Check for the same.
; CHECK: Not interchanging loops. Cannot prove legality.

define void @reduction_03(i32 %N) {
entry:
%cmp35 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -168,14 +164,6 @@ for.cond1.for.inc17_crit_edge: ; preds = %for.cond4.for.end_c
for.end19: ; preds = %for.cond1.for.inc17_crit_edge, %entry
ret void
}
;; Not tightly nested. Do not interchange.
;; Not interchanged hence the phi's in the inner loop will not be split. Check for the same.
; CHECK-LABEL: @reduction_03
; CHECK: for.body6: ; preds = %for.body6.preheader, %for.body6
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body6 ], [ 1, %for.body6.preheader ]
; CHECK: %add31 = phi i32 [ %add, %for.body6 ], [ %X.promoted, %for.body6.preheader ]



;; Multiple use of reduction not safe. Do not interchange.
;; for( int i=1;i<N;i++)
Expand All @@ -184,6 +172,10 @@ for.end19: ; preds = %for.cond1.for.inc17
;; X+=A[k][j];
;; Y+=X;
;; }

;; Not interchanged hence the phi's in the inner loop will not be split. Check for the same.
; CHECK: Not interchanging loops. Cannot prove legality.

define void @reduction_04(i32 %N) {
entry:
%cmp28 = icmp sgt i32 %N, 1
Expand Down Expand Up @@ -228,8 +220,3 @@ for.inc13: ; preds = %for.cond4.for.inc10
for.end15: ; preds = %for.inc13, %entry
ret void
}
;; Not interchanged hence the phi's in the inner loop will not be split. Check for the same.
; CHECK-LABEL: @reduction_04
; CHECK: for.body6: ; preds = %for.body6.preheader, %for.body6
; CHECK: %indvars.iv = phi i64 [ %indvars.iv.next, %for.body6 ], [ 1, %for.body6.preheader ]
; CHECK: %add925 = phi i32 [ %add9, %for.body6 ], [ %Y.promoted, %for.body6.preheader ]