1*e11354c0SNikita Popov; RUN: opt -S -loop-rotate -verify-memoryssa < %s | FileCheck %s
29e6a1e57SArthur Eubanks; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop(loop-rotate)' < %s | FileCheck %s
39e6a1e57SArthur Eubanks; RUN: opt -S -passes='require<targetir>,require<assumptions>,loop-mssa(loop-rotate)' -verify-memoryssa  < %s | FileCheck %s
4cee313d2SEric Christopher
5cee313d2SEric Christophertarget 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"
6cee313d2SEric Christophertarget triple = "x86_64-apple-darwin10.0.0"
7cee313d2SEric Christopher
8cee313d2SEric Christopher; PR5319 - The "arrayidx" gep should be hoisted, not duplicated.  We should
9cee313d2SEric Christopher; end up with one phi node.
10cee313d2SEric Christopherdefine void @test1() nounwind ssp {
11cee313d2SEric Christopher; CHECK-LABEL: @test1(
12cee313d2SEric Christopherentry:
13cee313d2SEric Christopher  %array = alloca [20 x i32], align 16
14cee313d2SEric Christopher  br label %for.cond
15cee313d2SEric Christopher
16cee313d2SEric Christopherfor.cond:                                         ; preds = %for.body, %entry
17cee313d2SEric Christopher  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
18cee313d2SEric Christopher  %cmp = icmp slt i32 %i.0, 100
19cee313d2SEric Christopher  %arrayidx = getelementptr inbounds [20 x i32], [20 x i32]* %array, i64 0, i64 0
20cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
21cee313d2SEric Christopher
22cee313d2SEric Christopher; CHECK: for.body:
23cee313d2SEric Christopher; CHECK-NEXT: phi i32 [ 0
24cee313d2SEric Christopher; CHECK-NEXT: store i32 0
25cee313d2SEric Christopher
26cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
27cee313d2SEric Christopher  store i32 0, i32* %arrayidx, align 16
28cee313d2SEric Christopher  %inc = add nsw i32 %i.0, 1
29cee313d2SEric Christopher  br label %for.cond
30cee313d2SEric Christopher
31cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
32cee313d2SEric Christopher  %arrayidx.lcssa = phi i32* [ %arrayidx, %for.cond ]
33cee313d2SEric Christopher  call void @g(i32* %arrayidx.lcssa) nounwind
34cee313d2SEric Christopher  ret void
35cee313d2SEric Christopher}
36cee313d2SEric Christopher
37cee313d2SEric Christopherdeclare void @g(i32*)
38cee313d2SEric Christopher
39cee313d2SEric Christopher; CHECK-LABEL: @test2(
40cee313d2SEric Christopherdefine void @test2() nounwind ssp {
41cee313d2SEric Christopherentry:
42cee313d2SEric Christopher  %array = alloca [20 x i32], align 16
43cee313d2SEric Christopher  br label %for.cond
44cee313d2SEric Christopher
45cee313d2SEric Christopherfor.cond:                                         ; preds = %for.body, %entry
46cee313d2SEric Christopher  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
47cee313d2SEric Christopher  %cmp = icmp slt i32 %i.0, 100
48cee313d2SEric Christopher; CHECK: call void @f
49cee313d2SEric Christopher; CHECK-NOT: call void @f
50cee313d2SEric Christopher  call void @f() noduplicate
51cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
52cee313d2SEric Christopher
53cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
54cee313d2SEric Christopher  %inc = add nsw i32 %i.0, 1
55cee313d2SEric Christopher  call void @h()
56cee313d2SEric Christopher  br label %for.cond
57cee313d2SEric Christopher
58cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
59cee313d2SEric Christopher  ret void
60cee313d2SEric Christopher; CHECK: }
61cee313d2SEric Christopher}
62cee313d2SEric Christopher
63cee313d2SEric Christopherdeclare void @f() noduplicate
64cee313d2SEric Christopherdeclare void @h()
65