xref: /llvm-project/llvm/test/Transforms/LoopRotate/phi-duplicate.ll (revision e730e7d2aa403cc87cc7ce9021ad035b385f4357)
1a11faeedSBjorn Pettersson; RUN: opt -S -passes=loop-rotate -verify-memoryssa < %s | FileCheck %s
2cee313d2SEric 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"
3cee313d2SEric Christophertarget triple = "x86_64-apple-darwin10.0"
4cee313d2SEric Christopher
5cee313d2SEric Christopher; PR5837
6*e730e7d2SNikita Popovdefine void @test(i32 %N, ptr %G) nounwind ssp {
7cee313d2SEric Christopherentry:
8cee313d2SEric Christopher  br label %for.cond
9cee313d2SEric Christopher
10cee313d2SEric Christopherfor.cond:                                         ; preds = %for.body, %entry
11cee313d2SEric Christopher  %j.0 = phi i64 [ 1, %entry ], [ %inc, %for.body ] ; <i64> [#uses=5]
12cee313d2SEric Christopher  %cmp = icmp slt i64 %j.0, 1000                  ; <i1> [#uses=1]
13cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
14cee313d2SEric Christopher
15cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
16*e730e7d2SNikita Popov  %arrayidx = getelementptr inbounds double, ptr %G, i64 %j.0 ; <ptr> [#uses=1]
17*e730e7d2SNikita Popov  %tmp3 = load double, ptr %arrayidx                  ; <double> [#uses=1]
18cee313d2SEric Christopher  %sub = sub i64 %j.0, 1                          ; <i64> [#uses=1]
19*e730e7d2SNikita Popov  %arrayidx6 = getelementptr inbounds double, ptr %G, i64 %sub ; <ptr> [#uses=1]
20*e730e7d2SNikita Popov  %tmp7 = load double, ptr %arrayidx6                 ; <double> [#uses=1]
21cee313d2SEric Christopher  %add = fadd double %tmp3, %tmp7                 ; <double> [#uses=1]
22*e730e7d2SNikita Popov  %arrayidx10 = getelementptr inbounds double, ptr %G, i64 %j.0 ; <ptr> [#uses=1]
23*e730e7d2SNikita Popov  store double %add, ptr %arrayidx10
24cee313d2SEric Christopher  %inc = add nsw i64 %j.0, 1                      ; <i64> [#uses=1]
25cee313d2SEric Christopher  br label %for.cond
26cee313d2SEric Christopher
27cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond
28cee313d2SEric Christopher  ret void
29cee313d2SEric Christopher}
30cee313d2SEric Christopher
31cee313d2SEric Christopher; Should only end up with one phi.
32cee313d2SEric Christopher; CHECK-LABEL:      define void @test(
33cee313d2SEric Christopher; CHECK-NEXT: entry:
34cee313d2SEric Christopher; CHECK-NEXT:   br label %for.body
35cee313d2SEric Christopher; CHECK:      for.body:
36cee313d2SEric Christopher; CHECK-NEXT:   %j.01 = phi i64
37cee313d2SEric Christopher; CHECK-NOT:  br
38cee313d2SEric Christopher; CHECK:   br i1 %cmp, label %for.body, label %for.end
39cee313d2SEric Christopher; CHECK:      for.end:
40cee313d2SEric Christopher; CHECK-NEXT:        ret void
41