Skip to content

Commit 8ada887

Browse files
authored
[unbox] Fix folding of if-cascade (#362)
1 parent 52bb24a commit 8ada887

File tree

14 files changed

+118
-20
lines changed

14 files changed

+118
-20
lines changed

aeneas/src/mach/MachLowering.v3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ class MachLowering(mach: MachProgram, compiler: Compiler, config: MachLoweringCo
10091009
i_cmp2.facts |= Facts.O_NO_NAN_CHECK; // NaN handled by first check
10101010
ifc.addCase(i_cmp2);
10111011
ifc.endCase(i_false);
1012-
ifc.addElse();
1012+
ifc.addElse(); // TODO: suspicious
10131013
var i_cmp = genIntTruncFEqual(i_old.source, ft, ett, i_x);
10141014
ifc.endCase(i_cmp);
10151015
var i_new = ifc.finish();
@@ -1042,7 +1042,7 @@ class MachLowering(mach: MachProgram, compiler: Compiler, config: MachLoweringCo
10421042
var i_gteq = apply(i_old.source, ft.opcache().opGteq, [i_x, i_maxf]);
10431043
ifc.addCase(i_gteq);
10441044
ifc.endCase(i_false);
1045-
ifc.addElse();
1045+
ifc.addElse(); // TODO: suspicious addElse
10461046
var i_cmp = genIntTruncFEqual(i_old.source, ft, ett, i_x);
10471047
ifc.endCase(i_cmp);
10481048
var i_new = ifc.finish();

aeneas/src/main/Version.v3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
// Updated by VCS scripts. DO NOT EDIT.
55
component Version {
6-
def version: string = "III-9.1801";
6+
def version: string = "III-9.1802";
77
var buildData: string;
88
}

aeneas/src/ssa/SsaBuilder.v3

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,10 @@ class SsaBuilder {
647647
}
648648
// ClassAlloc[new](args)
649649
def opClassAlloc(m: IrSpec, x: Array<SsaInstr>) -> SsaInstr {
650-
if (m.member == null) return add(V3Op.newEmptyClassAlloc(m.receiver), Ssa.NO_INSTRS, Fact.V_NON_ZERO);
651-
return add(V3Op.newClassAlloc(m), x, Fact.V_NON_ZERO);
650+
var facts: Fact.set = Fact.V_NON_ZERO;
651+
//TODO if (V3.isVariant(m.receiver)) facts |= Fact.O_PURE;
652+
if (m.member == null) return add(V3Op.newEmptyClassAlloc(m.receiver), Ssa.NO_INSTRS, facts);
653+
return add(V3Op.newClassAlloc(m), x, facts);
652654
}
653655
// (Component|Class|Variant)GetField[f](x)
654656
def opGetField(f: IrSpec, x: SsaInstr) -> SsaInstr {
@@ -875,29 +877,22 @@ class SsaIfCascade {
875877
fblock = null;
876878
}
877879
def endCase(val: SsaInstr) {
878-
if (builder.end) return;
879-
if (varType != null) {
880-
if (val == null) builder.context.fail("SsaIfCascade variable must be non-null on this path");
881-
phiInputs.put(val);
880+
if (!builder.end) {
881+
if (varType != null) {
882+
if (val == null) builder.context.fail("SsaIfCascade variable must be non-null on this path");
883+
phiInputs.put(val);
884+
}
885+
builder.addGoto(merge);
882886
}
883-
builder.addGoto(merge);
884887
at(fblock);
885888
}
886889
private def addIf0(cond: SsaInstr, not: bool) {
887890
if (builder.end) return;
888891
var tb = SsaBlock.new(), fb = SsaBlock.new();
889892
if (not) builder.addIf(cond, fb, tb);
890893
else builder.addIf(cond, tb, fb);
891-
if (tb.preds.length == 0) { // true case eliminated
892-
at(fb);
893-
fblock = null;
894-
} else if (fb.preds.length == 0) { // false case eliminated
895-
at(tb);
896-
fblock = null;
897-
} else {
898-
at(tb);
899-
fblock = fb;
900-
}
894+
at(tb);
895+
fblock = fb;
901896
}
902897
def finish() -> SsaInstr {
903898
if (fblock != null) builder.context.fail("SsaIfCascade: ended before else clause");

doc/aeneas-issues.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ ______ ______ __ _ ______ ______ ______ _____ ______ ______ _ _ ______ _
2727

2828
-- priority (primarily for Wizard) -----
2929
new type representation
30+
TypeSystem.computeCast
3031
-target=wasmgc
3132
unbox and pack variants
3233
canonicalize equivalent variant records
3334
threads
35+
fix and turn on inlining and -O3
36+
fold using SSA interpreter
3437

3538
-- wasm[gc] issues -----
3639
new type representation for structs, arrays, funcs

test/float/query02.v3

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@execute -1=false; 1=true
2+
var f = 0.1f;
3+
var g = 33f;
4+
5+
def main(a: int) -> bool {
6+
return if(a < 0, int.?(f), int.?(g));
7+
}

test/float/query03.v3

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@execute -1=false; 1=true
2+
var f = 0.1d;
3+
var g = 33d;
4+
5+
def main(a: int) -> bool {
6+
return if(a < 0, int.?(f), int.?(g));
7+
}

test/variants/ub_const00.v3

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@execute =13
2+
type A #unboxed {
3+
case X;
4+
case Y(x: int);
5+
}
6+
7+
def main() -> int {
8+
var a = A.Y(13);
9+
return getx(a);
10+
}
11+
def getx = A.Y.x;

test/variants/ub_const01.v3

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@execute =13
2+
type A #unboxed {
3+
case X;
4+
case Y(x: int);
5+
}
6+
7+
def main() -> int {
8+
var a = [A.Y(13), A.Y(13)];
9+
return getx(a[0]);
10+
}
11+
def getx = A.Y.x;

test/variants/ub_const02.v3

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@execute =13
2+
type A #unboxed {
3+
case X;
4+
case Y(x: int);
5+
}
6+
7+
def main() -> int {
8+
var a = A.Y(13);
9+
return getx(a);
10+
}
11+
def getx(a: A) -> int {
12+
match (a) {
13+
X => return 11;
14+
Y(x) => return x;
15+
}
16+
}

test/variants/ub_const03.v3

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@execute =true
2+
type A {
3+
case X;
4+
case Y(x: int);
5+
}
6+
7+
var x = A.Y(14);
8+
var y = A.Y(14);
9+
10+
def main() -> bool {
11+
return x == y;
12+
}

0 commit comments

Comments
 (0)