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