llvm.org GIT mirror llvm / ecdc1aa
Fix overconfident assert in ScalarEvolution::isImpliedViaMerge We can have AddRec with loops having many predecessors. This changes an assert to an early return. Differential Revision: https://reviews.llvm.org/D48766 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335965 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Shirokiy 2 years ago
2 changed file(s) with 130 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
97119711 // AddRec. It means that there is a loop which has both AddRec and Unknown
97129712 // PHIs, for it we can compare incoming values of AddRec from above the loop
97139713 // and latch with their respective incoming values of LPhi.
9714 assert(LPhi->getNumIncomingValues() == 2 &&
9715 "Phi node standing in loop header does not have exactly 2 inputs?");
9714 // TODO: Generalize to handle loops with many inputs in a header.
9715 if (LPhi->getNumIncomingValues() != 2) return false;
9716
97169717 auto *RLoop = RAR->getLoop();
97179718 auto *Predecessor = RLoop->getLoopPredecessor();
97189719 assert(Predecessor && "Loop with AddRec with no predecessor?");
0 ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
1
2 ; Check that isImpliedViaMerge wouldn't crash when trying to prove
3 ; SCEVUnknown and AddRec with phi having many inputs
4 ; CHECK: @foo
5
6 define void @foo(i1 %cond) {
7 osr.type.merge79:
8 br label %bci_329
9
10 bci_329: ; preds = %bci_337, %bci_326, %osr.type.merge79
11 %local_7_ = phi i32 [ 0, %osr.type.merge79 ], [ %local_7_113, %bci_326 ], [ %local_7_, %bci_337 ]
12 br i1 %cond, label %bci_360, label %bci_337
13
14 bci_360: ; preds = %bci_329
15 %0 = phi i32 [ %local_7_, %bci_329 ]
16 %1 = icmp sge i32 %0, 451
17 br i1 %1, label %bci_371, label %bci_326
18
19 bci_371: ; preds = %bci_304, %bci_360
20 %local_2_132 = phi i32 [ 0, %bci_360 ], [ %local_2_188, %bci_304 ]
21 %local_7_137 = phi i32 [ 0, %bci_360 ], [ %local_7_217, %bci_304 ]
22 %local_8_138 = phi i32 [ 0, %bci_360 ], [ %local_8_194, %bci_304 ]
23 %local_11_141 = phi i32 [ 0, %bci_360 ], [ %local_11_197, %bci_304 ]
24 %2 = phi i1 [ %1, %bci_360 ], [ false, %bci_304 ]
25 br i1 %2, label %bci_562, label %never_deopt
26
27 bci_562: ; preds = %done437, %done405, %done395, %bci_407, %not_zero322, %bci_221, %bci_371
28 %local_2_164 = phi i32 [ %local_2_132, %bci_371 ], [ %9, %not_zero322 ], [ %local_2_188, %bci_407 ], [ %result396, %done395 ], [ %local_2_188, %bci_221 ], [ %local_2_188, %done405 ], [ %local_2_188, %done437 ]
29 %local_7_169 = phi i32 [ %local_7_137, %bci_371 ], [ %local_7_217, %not_zero322 ], [ %local_7_217, %bci_407 ], [ %local_7_217, %done395 ], [ %local_7_217, %bci_221 ], [ %local_7_217, %done405 ], [ %local_7_217, %done437 ]
30 %local_8_170 = phi i32 [ %local_8_138, %bci_371 ], [ %local_8_194, %not_zero322 ], [ %local_8_194, %bci_407 ], [ %local_8_194, %done395 ], [ %local_8_194, %bci_221 ], [ %local_8_194, %done405 ], [ %local_8_194, %done437 ]
31 %local_11_173 = phi i32 [ %local_11_141, %bci_371 ], [ %local_11_197, %not_zero322 ], [ %local_11_197, %bci_407 ], [ %local_11_197, %done395 ], [ %local_11_197, %bci_221 ], [ %local_11_197, %done405 ], [ %local_11_197, %done437 ]
32 br label %bci_604
33
34 bci_604: ; preds = %not_subtype, %bci_565, %bci_562
35 %local_2_188 = phi i32 [ %local_2_164, %bci_562 ], [ %9, %bci_565 ], [ %9, %not_subtype ]
36 %local_7_193 = phi i32 [ %local_7_169, %bci_562 ], [ %local_7_217, %bci_565 ], [ %local_7_217, %not_subtype ]
37 %local_8_194 = phi i32 [ %local_8_170, %bci_562 ], [ %local_8_194, %bci_565 ], [ %local_8_194, %not_subtype ]
38 %local_11_197 = phi i32 [ %local_11_173, %bci_562 ], [ %local_11_197, %bci_565 ], [ %local_11_197, %not_subtype ]
39 %3 = add i32 1, %local_7_193
40 br label %bci_199
41
42 bci_199: ; preds = %bci_591, %bci_604
43 %local_7_217 = phi i32 [ %3, %bci_604 ], [ %6, %bci_591 ]
44 %4 = mul i32 %local_2_188, %local_8_194
45 %5 = icmp sge i32 %local_7_217, %4
46 br i1 %5, label %bci_610, label %bci_216
47
48 bci_610: ; preds = %bci_199
49 ret void
50
51 bci_216: ; preds = %bci_199
52 br i1 %cond, label %bci_591, label %bci_221
53
54 bci_591: ; preds = %bci_216
55 %6 = add i32 1, %local_7_217
56 br label %bci_199
57
58 bci_221: ; preds = %bci_216
59 %7 = srem i32 %local_7_217, 6
60 %8 = add i32 %7, 114
61 switch i32 %8, label %done405 [
62 i32 114, label %bci_562
63 i32 116, label %bci_304
64 i32 117, label %bci_395
65 i32 118, label %bci_407
66 i32 119, label %bci_419
67 ]
68
69 bci_419: ; preds = %bci_221
70 %9 = sub i32 %local_2_188, %local_11_197
71 br label %bci_435
72
73 bci_435: ; preds = %not_zero322, %bci_419
74 br i1 %cond, label %not_zero265, label %never_deopt
75
76 not_zero265: ; preds = %bci_435
77 br i1 %cond, label %in_bounds, label %out_of_bounds
78
79 in_bounds: ; preds = %not_zero265
80 br i1 %cond, label %not_zero322, label %never_deopt
81
82 not_zero322: ; preds = %in_bounds
83 br i1 %cond, label %bci_562, label %bci_435
84
85 bci_407: ; preds = %bci_221
86 br label %bci_562
87
88 bci_395: ; preds = %bci_221
89 br i1 %cond, label %done395, label %general_case394
90
91 general_case394: ; preds = %bci_395
92 %10 = srem i32 %local_2_188, 0
93 br label %done395
94
95 done395: ; preds = %general_case394, %bci_395
96 %result396 = phi i32 [ %10, %general_case394 ], [ 0, %bci_395 ]
97 br label %bci_562
98
99 bci_304: ; preds = %bci_221
100 br i1 %cond, label %bci_371, label %bci_326
101
102 done405: ; preds = %bci_221
103 br i1 %cond, label %bci_562, label %done437
104
105 done437: ; preds = %done405
106 br label %bci_562
107
108 bci_326: ; preds = %bci_304, %bci_360
109 %local_7_113 = phi i32 [ %local_7_, %bci_360 ], [ %local_7_217, %bci_304 ]
110 br label %bci_329
111
112 bci_337: ; preds = %bci_329
113 br label %bci_329
114
115 never_deopt: ; preds = %in_bounds, %bci_435, %bci_371
116 ret void
117
118 out_of_bounds: ; preds = %not_zero265
119 br i1 %cond, label %bci_565, label %not_subtype
120
121 bci_565: ; preds = %out_of_bounds
122 br label %bci_604
123
124 not_subtype: ; preds = %out_of_bounds
125 br label %bci_604
126 }