Skip to content

Commit 2b3f2a3

Browse files
committed
bug in speculative loop opt
1 parent 5f20060 commit 2b3f2a3

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

src/common/SplitEffects.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ trait SplitEffectsExpFat extends IfThenElseFatExp with WhileExp with PreviousIte
1717

1818
// TODO: SimpleLoops
1919

20+
// FIXME: wo do not account for mutable objectes allocated in a loop
21+
// (see test8-speculative6)
22+
2023
override def reflectEffectInternal[A:Manifest](x: Def[A], u: Summary)(implicit pos: SourceContext): Exp[A] = x match {
2124
case IfThenElse(cond, thenp, elsep) =>
2225
val affected = (u.mayRead ++ u.mayWrite).distinct
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
promoting to effect: Sym(65)=Reflect(PreviousIteration(Sym(58)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(54)))
2+
depends on Sym(2)
3+
promoting to effect: Sym(71)=Reflect(PreviousIteration(Sym(57)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(54)))
4+
depends on Sym(2)
5+
promoting to effect: Sym(81)=Reflect(PreviousIteration(Sym(58)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(54)))
6+
depends on Sym(2)
7+
promoting to effect: Sym(87)=Reflect(PreviousIteration(Sym(57)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(54)))
8+
depends on Sym(2)
9+
promoting to effect: Sym(100)=Reflect(While(Block(Sym(98)),Block(Sym(99))),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(54)))
10+
depends on Sym(2)
11+
promoting to effect: Sym(127)=Reflect(PreviousIteration(Sym(120)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(116)))
12+
depends on Sym(2)
13+
promoting to effect: Sym(133)=Reflect(PreviousIteration(Sym(119)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(116)))
14+
depends on Sym(2)
15+
promoting to effect: Sym(143)=Reflect(PreviousIteration(Sym(120)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(116)))
16+
depends on Sym(2)
17+
promoting to effect: Sym(149)=Reflect(PreviousIteration(Sym(119)),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(116)))
18+
depends on Sym(2)
19+
promoting to effect: Sym(162)=Reflect(While(Block(Sym(160)),Block(Sym(161))),Summary(false,false,false,false,false,false,List(Sym(2)),List(Sym(2)),List(),List()),List(Sym(2), Sym(116)))
20+
depends on Sym(2)
21+
/*****************************************
22+
Emitting Generated Code
23+
*******************************************/
24+
class Test extends ((Int)=>(Unit)) {
25+
def apply(x0:Int): Unit = {
26+
var x176 = null.asInstanceOf[Unit]
27+
var x180 = null.asInstanceOf[Unit]
28+
val x1 = println("FIXME -- WRONG RESULT")
29+
var x2: Int = 0
30+
var x118: Int = 0
31+
while ({ // List(Sym(176), Sym(180))
32+
// dummy placeholder for previous iteration: List(Sym(112), Sym(111)) = Sym(4) / List(Sym(1), Sym(2), Sym(176))
33+
val x113 = x2
34+
val x114 = x113 < 10
35+
x114
36+
}) {
37+
var x166 = null.asInstanceOf[Unit]
38+
var x162 = null.asInstanceOf[Unit]
39+
var x170 = null.asInstanceOf[Unit]
40+
// dummy placeholder for previous iteration: List(Sym(116), Sym(117)) = Sym(3) / List(Sym(2), Sym(176), Sym(1))
41+
while ({ // List(Sym(166), Sym(162), Sym(170))
42+
// dummy placeholder for previous iteration: List(Sym(144), Sym(143), Sym(145)) = Sym(120) / List(Sym(118), Sym(166), Sym(2), Sym(116), Sym(117))
43+
val x146 = x118
44+
val x147 = x146 < 10
45+
x147
46+
}) {
47+
// dummy placeholder for previous iteration: List(Sym(150), Sym(149), Sym(151)) = Sym(119) / List(Sym(118), Sym(166), Sym(2), Sym(116), Sym(117))
48+
val x152 = println("test")
49+
val x153 = x2
50+
val x154 = println(x153)
51+
val x155 = x118
52+
val x156 = println(x155)
53+
val x157 = x118 += 1
54+
}
55+
val x171 = x2 += 1
56+
}
57+
()
58+
}
59+
}
60+
/*****************************************
61+
End of Generated Code
62+
*******************************************/
63+
promoting to effect: Sym(248)=Reflect(PreviousIteration(Sym(241)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(237)))
64+
depends on Sym(185)
65+
promoting to effect: Sym(254)=Reflect(PreviousIteration(Sym(240)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(237)))
66+
depends on Sym(185)
67+
promoting to effect: Sym(264)=Reflect(PreviousIteration(Sym(241)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(237)))
68+
depends on Sym(185)
69+
promoting to effect: Sym(270)=Reflect(PreviousIteration(Sym(240)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(237)))
70+
depends on Sym(185)
71+
promoting to effect: Sym(283)=Reflect(While(Block(Sym(281)),Block(Sym(282))),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(237)))
72+
depends on Sym(185)
73+
promoting to effect: Sym(310)=Reflect(PreviousIteration(Sym(303)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(299)))
74+
depends on Sym(185)
75+
promoting to effect: Sym(316)=Reflect(PreviousIteration(Sym(302)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(299)))
76+
depends on Sym(185)
77+
promoting to effect: Sym(326)=Reflect(PreviousIteration(Sym(303)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(299)))
78+
depends on Sym(185)
79+
promoting to effect: Sym(332)=Reflect(PreviousIteration(Sym(302)),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(299)))
80+
depends on Sym(185)
81+
promoting to effect: Sym(345)=Reflect(While(Block(Sym(343)),Block(Sym(344))),Summary(false,false,false,false,false,false,List(Sym(185)),List(Sym(185)),List(),List()),List(Sym(185), Sym(299)))
82+
depends on Sym(185)
83+
compilation: ok
84+
FIXME -- WRONG RESULT
85+
test
86+
0
87+
0
88+
test
89+
0
90+
1
91+
test
92+
0
93+
2
94+
test
95+
0
96+
3
97+
test
98+
0
99+
4
100+
test
101+
0
102+
5
103+
test
104+
0
105+
6
106+
test
107+
0
108+
7
109+
test
110+
0
111+
8
112+
test
113+
0
114+
9

test-src/epfl/test8-effects/TestSpeculative.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,32 @@ class TestSpeculative extends FileDiffSuite {
220220
assertFileEqualsCheck(prefix+"speculative5")
221221
}
222222

223+
// FIXME: this one breaks. Variable j is lifted to
224+
// top scope because it is not part of the mayWrite
225+
// summary of the inner loop.
226+
def testSpeculative6 = {
227+
withOutFile(prefix+"speculative6") {
228+
// test simple copy propagation through variable
229+
trait Prog extends DSL {
230+
def test(x: Rep[Int]) = {
231+
print("FIXME -- WRONG RESULT")
232+
var i = 0
233+
while (i < 10) {
234+
var j = 0
235+
while (j < 10) {
236+
print("test")
237+
print(i)
238+
print(j)
239+
j += 1
240+
}
241+
i += 1
242+
}
243+
}
244+
}
245+
new Prog with Impl
246+
}
247+
assertFileEqualsCheck(prefix+"speculative6")
248+
}
249+
250+
223251
}

0 commit comments

Comments
 (0)