llvm.org GIT mirror llvm / b001759
LSR: Reuse the post-inc expansion of expressions. This avoids unnecessary expansion of expressions and allows the SCEV expander to work on expression DAGs, not just trees. Fixes PR11090. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141870 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 9 years ago
2 changed file(s) with 125 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11191119 BasicBlock *LatchBlock = L->getLoopLatch();
11201120 assert(LatchBlock && "PostInc mode requires a unique loop latch!");
11211121 Result = PN->getIncomingValueForBlock(LatchBlock);
1122
1123 // For an expansion to use the postinc form, the client must call
1124 // expandCodeFor with an InsertPoint that is either outside the PostIncLoop
1125 // or dominated by IVIncInsertPos.
1126 assert((!isa(Result) ||
1127 SE.DT->dominates(cast(Result),
1128 Builder.GetInsertPoint())) &&
1129 "postinc expansion does not dominate use");
11221130 }
11231131
11241132 // Re-apply any non-loop-dominating scale.
14091417 Value *V = visit(S);
14101418
14111419 // Remember the expanded value for this SCEV at this location.
1412 if (PostIncLoops.empty())
1413 InsertedExpressions[std::make_pair(S, InsertPt)] = V;
1420 //
1421 // This is independent of PostIncLoops. The mapped value simply materializes
1422 // the expression at this insertion point. If the mapped value happened to be
1423 // a postinc expansion, it could be reused by a non postinc user, but only if
1424 // its insertion point was already at the head of the loop.
1425 InsertedExpressions[std::make_pair(S, InsertPt)] = V;
14141426
14151427 restoreInsertPoint(SaveInsertBB, SaveInsertPt);
14161428 return V;
0 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
1 ;
2 ; Test TransformForPostIncUse and LSR's expansion of expressions in
3 ; post-inc form to ensure the implementation can handle expressions
4 ; DAGs, not just trees.
5
6 target triple = "x86_64-apple-darwin"
7
8 ; Verify that -loop-reduce runs without "hanging" and reuses post-inc
9 ; expansions.
10 ; CHECK: @test
11 ; CHECK: icmp
12 ; CHECK: icmp
13 ; CHECK: icmp
14 ; CHECK: icmp
15 ; CHECK: icmp
16 ; CHECK: icmp
17 ; CHECK: icmp
18 ; CHECK: icmp
19 ; CHECK: icmp
20 ; CHECK: icmp
21 ; CHECK: icmp
22 ; CHECK: icmp
23 ; CHECK: icmp
24 ; CHECK: icmp
25 ; CHECK: icmp
26 ; CHECK: icmp
27 ; CHECK: icmp
28 ; CHECK-NOT: icmp
29 define void @test(i8* %base, i32 %a0) nounwind {
30 entry:
31 br label %bb1
32 bb1:
33 %n0 = sub i32 0, %a0
34 %t0 = icmp ugt i32 %n0, -4
35 %m0 = select i1 %t0, i32 %n0, i32 -4
36 %a1 = add i32 %m0, %a0
37 %n1 = sub i32 0, %a1
38 %t1 = icmp ugt i32 %n1, -4
39 %m1 = select i1 %t1, i32 %n1, i32 -4
40 %a2 = add i32 %m1, %a1
41 %n2 = sub i32 0, %a2
42 %t2 = icmp ugt i32 %n2, -4
43 %m2 = select i1 %t2, i32 %n2, i32 -4
44 %a3 = add i32 %m2, %a2
45 %n3 = sub i32 0, %a3
46 %t3 = icmp ugt i32 %n3, -4
47 %m3 = select i1 %t3, i32 %n3, i32 -4
48 %a4 = add i32 %m3, %a3
49 %n4 = sub i32 0, %a4
50 %t4 = icmp ugt i32 %n4, -4
51 %m4 = select i1 %t4, i32 %n4, i32 -4
52 %a5 = add i32 %m4, %a4
53 %n5 = sub i32 0, %a5
54 %t5 = icmp ugt i32 %n5, -4
55 %m5 = select i1 %t5, i32 %n5, i32 -4
56 %a6 = add i32 %m5, %a5
57 %n6 = sub i32 0, %a6
58 %t6 = icmp ugt i32 %n6, -4
59 %m6 = select i1 %t6, i32 %n6, i32 -4
60 %a7 = add i32 %m6, %a6
61 %n7 = sub i32 0, %a7
62 %t7 = icmp ugt i32 %n7, -4
63 %m7 = select i1 %t7, i32 %n7, i32 -4
64 %a8 = add i32 %m7, %a7
65 %n8 = sub i32 0, %a8
66 %t8 = icmp ugt i32 %n8, -4
67 %m8 = select i1 %t8, i32 %n8, i32 -4
68 %a9 = add i32 %m8, %a8
69 %n9 = sub i32 0, %a9
70 %t9 = icmp ugt i32 %n9, -4
71 %m9 = select i1 %t9, i32 %n9, i32 -4
72 %a10 = add i32 %m9, %a9
73 %n10 = sub i32 0, %a10
74 %t10 = icmp ugt i32 %n10, -4
75 %m10 = select i1 %t10, i32 %n10, i32 -4
76 %a11 = add i32 %m10, %a10
77 %n11 = sub i32 0, %a11
78 %t11 = icmp ugt i32 %n11, -4
79 %m11 = select i1 %t11, i32 %n11, i32 -4
80 %a12 = add i32 %m11, %a11
81 %n12 = sub i32 0, %a12
82 %t12 = icmp ugt i32 %n12, -4
83 %m12 = select i1 %t12, i32 %n12, i32 -4
84 %a13 = add i32 %m12, %a12
85 %n13 = sub i32 0, %a13
86 %t13 = icmp ugt i32 %n13, -4
87 %m13 = select i1 %t13, i32 %n13, i32 -4
88 %a14 = add i32 %m13, %a13
89 %n14 = sub i32 0, %a14
90 %t14 = icmp ugt i32 %n14, -4
91 %m14 = select i1 %t14, i32 %n14, i32 -4
92 %a15 = add i32 %m14, %a14
93 %n15 = sub i32 0, %a15
94 %t15 = icmp ugt i32 %n15, -4
95 %m15 = select i1 %t15, i32 %n15, i32 -4
96 %a16 = add i32 %m15, %a15
97 %gep = getelementptr i8* %base, i32 %a16
98 %ofs = add i32 %a16, 4
99 %limit = getelementptr i8* %base, i32 %ofs
100 br label %loop
101
102 loop:
103 %iv = phi i8* [ %gep, %bb1 ], [ %inc, %loop ]
104 %inc = getelementptr inbounds i8* %iv, i64 1
105 %exitcond = icmp eq i8* %inc, %limit
106 br i1 %exitcond, label %loop, label %exit
107
108 exit:
109 ret void
110 }