• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; PR41445: This test checks the case when LSR split critical edge
2; and phi node has other pending fixup operands
3
4; RUN: opt -S -loop-reduce < %s | FileCheck %s
5
6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7target triple = "x86_64-unknown-linux-gnu"
8
9; We have %indvars.iv.lcssa phi node where 4 input operands
10; need to be rewritten: %tmp1, %tmp2, %tmp3, %tmp4.
11; When we try to rewrite %tmp1, we first split the critical edge.
12; All the other PHI inputs besides %tmp1 go to a new phi node.
13; This test checks that LSR is still able to rewrite %tmp2, %tmp3, %tmp4.
14define i32 @foo(i32* %A, i32 %t) {
15entry:
16  br label %loop.32
17
18loop.exit:                                        ; preds = %then.8.1, %then.8, %ifmerge.42, %ifmerge.38, %ifmerge.34, %then.34
19  %indvars.iv.lcssa = phi i64 [ 48, %then.8 ], [ 49, %then.8.1 ], [ %tmp4, %ifmerge.42 ], [ %tmp3, %ifmerge.38 ], [ %tmp2, %ifmerge.34 ], [ %tmp1, %then.34 ]
20  %tmp = trunc i64 %indvars.iv.lcssa to i32
21  br label %for.end
22
23for.end:                                          ; preds = %then.8.1, %ifmerge.8, %loop.exit
24  %i.0.lcssa = phi i32 [ %tmp, %loop.exit ], [ 50, %then.8.1 ], [ 50, %ifmerge.8 ]
25  ret i32 %i.0.lcssa
26
27; shl instruction will be dead eliminated when all it's uses will be rewritten.
28; CHECK-LABEL: loop.32:
29; CHECK-NOT: shl
30loop.32:                                          ; preds = %ifmerge.46, %entry
31  %i1.i64.0 = phi i64 [ 0, %entry ], [ %nextivloop.32, %ifmerge.46 ]
32  %tmp1 = shl i64 %i1.i64.0, 2
33  %tmp2 = or i64 %tmp1, 1
34  %arrayIdx = getelementptr inbounds i32, i32* %A, i64 %tmp2
35  %gepload = load i32, i32* %arrayIdx, align 4
36  %cmp.34 = icmp sgt i32 %gepload, %t
37  br i1 %cmp.34, label %then.34, label %ifmerge.34
38
39; CHECK-LABEL: then.34:
40then.34:                                          ; preds = %loop.32
41  %arrayIdx17 = getelementptr inbounds i32, i32* %A, i64 %tmp1
42  %gepload18 = load i32, i32* %arrayIdx17, align 4
43  %cmp.35 = icmp slt i32 %gepload18, %t
44  br i1 %cmp.35, label %loop.exit, label %ifmerge.34
45
46ifmerge.34:                                       ; preds = %then.34, %loop.32
47  %tmp3 = or i64 %tmp1, 2
48  %arrayIdx19 = getelementptr inbounds i32, i32* %A, i64 %tmp3
49  %gepload20 = load i32, i32* %arrayIdx19, align 4
50  %cmp.38 = icmp sgt i32 %gepload20, %t
51  %cmp.39 = icmp slt i32 %gepload, %t
52  %or.cond = and i1 %cmp.38, %cmp.39
53  br i1 %or.cond, label %loop.exit, label %ifmerge.38
54
55ifmerge.38:                                       ; preds = %ifmerge.34
56  %tmp4 = or i64 %tmp1, 3
57  %arrayIdx23 = getelementptr inbounds i32, i32* %A, i64 %tmp4
58  %gepload24 = load i32, i32* %arrayIdx23, align 4
59  %cmp.42 = icmp sgt i32 %gepload24, %t
60  %cmp.43 = icmp slt i32 %gepload20, %t
61  %or.cond55 = and i1 %cmp.42, %cmp.43
62  br i1 %or.cond55, label %loop.exit, label %ifmerge.42
63
64ifmerge.42:                                       ; preds = %ifmerge.38
65  %tmp5 = add i64 %tmp1, 4
66  %arrayIdx27 = getelementptr inbounds i32, i32* %A, i64 %tmp5
67  %gepload28 = load i32, i32* %arrayIdx27, align 4
68  %cmp.46 = icmp sgt i32 %gepload28, %t
69  %cmp.47 = icmp slt i32 %gepload24, %t
70  %or.cond56 = and i1 %cmp.46, %cmp.47
71  br i1 %or.cond56, label %loop.exit, label %ifmerge.46
72
73ifmerge.46:                                       ; preds = %ifmerge.42
74  %nextivloop.32 = add nuw nsw i64 %i1.i64.0, 1
75  %condloop.32 = icmp ult i64 %nextivloop.32, 12
76  br i1 %condloop.32, label %loop.32, label %loop.25
77
78loop.25:                                          ; preds = %ifmerge.46
79  %arrayIdx31 = getelementptr inbounds i32, i32* %A, i64 49
80  %gepload32 = load i32, i32* %arrayIdx31, align 4
81  %cmp.8 = icmp sgt i32 %gepload32, %t
82  br i1 %cmp.8, label %then.8, label %ifmerge.8
83
84then.8:                                           ; preds = %loop.25
85  %arrayIdx33 = getelementptr inbounds i32, i32* %A, i64 48
86  %gepload34 = load i32, i32* %arrayIdx33, align 4
87  %cmp.15 = icmp slt i32 %gepload34, %t
88  br i1 %cmp.15, label %loop.exit, label %ifmerge.8
89
90ifmerge.8:                                        ; preds = %then.8, %loop.25
91  %arrayIdx31.1 = getelementptr inbounds i32, i32* %A, i64 50
92  %gepload32.1 = load i32, i32* %arrayIdx31.1, align 4
93  %cmp.8.1 = icmp sgt i32 %gepload32.1, %t
94  br i1 %cmp.8.1, label %then.8.1, label %for.end
95
96then.8.1:                                         ; preds = %ifmerge.8
97  %arrayIdx33.1 = getelementptr inbounds i32, i32* %A, i64 49
98  %gepload34.1 = load i32, i32* %arrayIdx33.1, align 4
99  %cmp.15.1 = icmp slt i32 %gepload34.1, %t
100  br i1 %cmp.15.1, label %loop.exit, label %for.end
101}
102