aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analyzer.js23
-rw-r--r--tests/cases/legalizer_ta2.ll12
-rw-r--r--tests/cases/legalizer_ta2.txt1
3 files changed, 30 insertions, 6 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 15d66285..a1c009f2 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -221,11 +221,16 @@ function analyzer(data, sidePass) {
// accessible through ident$x, and not constants we need to parse then and there)
if (subItem != item && (!(subItem.intertype in UNUNFOLDABLE) ||
(subItem.intertype == 'value' && isNumber(subItem.ident) && isIllegalType(subItem.type)))) {
- var tempIdent = '$$emscripten$temp$' + (tempId++);
- subItem.assignTo = tempIdent;
- unfolded.unshift(subItem);
- fixUnfolded(subItem);
- return { intertype: 'value', ident: tempIdent, type: subItem.type };
+ if (item.intertype == 'phi') {
+ assert(subItem.intertype == 'value', 'We can only unfold illegal constants in phis');
+ // we must handle this in the phi itself, if we unfold normally it will not be pushed back with the phi
+ } else {
+ var tempIdent = '$$emscripten$temp$' + (tempId++);
+ subItem.assignTo = tempIdent;
+ unfolded.unshift(subItem);
+ fixUnfolded(subItem);
+ return { intertype: 'value', ident: tempIdent, type: subItem.type };
+ }
} else if (subItem.intertype == 'switch' && isIllegalType(subItem.type)) {
subItem.switchLabels.forEach(function(switchLabel) {
if (switchLabel.value[0] != '$') {
@@ -370,6 +375,12 @@ function analyzer(data, sidePass) {
var toAdd = [];
var elements = getLegalVars(item.assignTo, bits);
var j = 0;
+ var literalValues = {}; // special handling of literals - we cannot unfold them normally
+ value.params.map(function(param) {
+ if (isNumber(param.value.ident)) {
+ literalValues[param.value.ident] = getLegalLiterals(param.value.ident, bits);
+ }
+ });
elements.forEach(function(element) {
toAdd.push({
intertype: 'phi',
@@ -381,7 +392,7 @@ function analyzer(data, sidePass) {
label: param.label,
value: {
intertype: 'value',
- ident: param.value.ident + '$' + j,
+ ident: (param.value.ident in literalValues) ? literalValues[param.value.ident][j].ident : (param.value.ident + '$' + j),
type: 'i' + element.bits,
}
};
diff --git a/tests/cases/legalizer_ta2.ll b/tests/cases/legalizer_ta2.ll
index bb7220c8..fbb5dc5d 100644
--- a/tests/cases/legalizer_ta2.ll
+++ b/tests/cases/legalizer_ta2.ll
@@ -116,6 +116,18 @@ a26:
store i88 %a27, i88* bitcast ([300 x i8]* @globaliz to i88*), align 4
call i32 (i8*)* @puts(i8* bitcast ([300 x i8]* @globaliz to i8*))
+; phi with constants
+ br i1 %if, label %a17b, label %a26b
+
+a17b:
+ br label %a26b
+
+a26b:
+ %a27b = phi i64 [ 55, %a26 ], [ 57, %a17b ]
+ store i104 0, i104* %bundled, align 4 ; wipe it out
+ store i64 %a27b, i64* bitcast ([300 x i8]* @globaliz to i64*), align 4
+ call i32 (i8*)* @puts(i8* bitcast ([300 x i8]* @globaliz to i8*))
+
store i104 %ored, i104* %bundled, align 4
%iff = zext i1 %if to i64
switch i64 %iff, label %a50 [
diff --git a/tests/cases/legalizer_ta2.txt b/tests/cases/legalizer_ta2.txt
index 93ea1e23..c57b20f5 100644
--- a/tests/cases/legalizer_ta2.txt
+++ b/tests/cases/legalizer_ta2.txt
@@ -16,6 +16,7 @@ hello, war`d
hello, wor-d
hello, wor
hello, worl
+9
hello, war`d
hello, world
hello, w