1# RUN: llc -run-pass=codegenprepare -o - %s | FileCheck %s
2
3# REQUIRES: default_triple
4
5# This testcase without the accompanying fix triggers the assert
6# "Replacement PHI node is already replaced."
7
8--- |
9
10  define void @f1() {
11  entry:
12    %arrayidx = getelementptr inbounds [2 x i16], [2 x i16]* undef, i16 0, i16 2
13    %0 = bitcast i16* %arrayidx to i32*
14    %1 = bitcast [2 x i16]* undef to i32*
15    br label %for.cond
16
17  for.cond.loopexit:
18    br label %for.cond
19
20  for.cond:
21    %2 = phi i32* [ %0, %entry ], [ %12, %for.cond.loopexit ]
22    %3 = phi i32* [ %0, %entry ], [ %14, %for.cond.loopexit ]
23    br label %for.body
24
25  for.body:
26    %4 = phi i32* [ %3, %for.cond ], [ %14, %cleanup ]
27    %5 = phi i32* [ %2, %for.cond ], [ %13, %cleanup ]
28    %6 = phi i32* [ %2, %for.cond ], [ %12, %cleanup ]
29    br i1 undef, label %for.cond2.preheader, label %if.then
30
31  for.cond2.preheader:
32    br label %for.cond2
33
34  if.then:
35    store i32 undef, i32* %4, align 1
36    br label %cleanup
37
38  for.cond2:
39    %7 = phi i32* [ %10, %for.inc ], [ %6, %for.cond2.preheader ]
40    %8 = phi i32* [ %11, %for.inc ], [ %5, %for.cond2.preheader ]
41    %9 = phi i32* [ %11, %for.inc ], [ %4, %for.cond2.preheader ]
42    br i1 undef, label %for.inc, label %if.then5
43
44  if.then5:
45    br i1 icmp ne (i16 2, i16 0), label %cleanup.loopexit, label %if.end
46
47  if.end:
48    br label %for.inc
49
50  for.inc:
51    %10 = phi i32* [ %7, %if.end ], [ %1, %for.cond2 ]
52    %11 = phi i32* [ %8, %if.end ], [ %1, %for.cond2 ]
53    br label %for.cond2
54
55  cleanup.loopexit:
56    br label %cleanup
57
58  cleanup:
59    %12 = phi i32* [ %6, %if.then ], [ %7, %cleanup.loopexit ]
60    %13 = phi i32* [ %5, %if.then ], [ %8, %cleanup.loopexit ]
61    %14 = phi i32* [ %4, %if.then ], [ %9, %cleanup.loopexit ]
62    br i1 true, label %for.cond.loopexit, label %for.body
63  }
64
65...
66
67# Sanity check to verify that something got through.
68# CHECK-LABEL: entry:
69