From 7459e5af01fbe3a8e75e73783794b4cdffda34e9 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Fri, 5 Feb 2016 05:11:50 -0800 Subject: Fix select The ordering changed in: https://github.com/WebAssembly/spec/pull/221 Which changed the spec tests, breaking sexpr-wasm because it pulls in the spec tests. This was then fixed: https://github.com/WebAssembly/sexpr-wasm-prototype/commit/23dc368148fc7827a603e3853f5a40287eb9effe Which in turn breaks when binaryen feeds sexpr-wasm .wast files with the old select operand ordering. Note that this PR has new failures when running the torture tests in binaryen-shell: the order of evaluation is correct in binaryen-shell but isn't emitted properly by LLVM in the .s files. This will require another patch to fix LLVM. --- src/wasm2asm.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/wasm2asm.h') diff --git a/src/wasm2asm.h b/src/wasm2asm.h index c87e81eec..d8ac6376e 100644 --- a/src/wasm2asm.h +++ b/src/wasm2asm.h @@ -463,7 +463,7 @@ void Wasm2AsmBuilder::scanFunctionBody(Expression* curr) { } } void visitSelect(Select *curr) { - if (parent->isStatement(curr->condition) || parent->isStatement(curr->ifTrue) || parent->isStatement(curr->ifFalse)) { + if (parent->isStatement(curr->ifTrue) || parent->isStatement(curr->ifFalse) || parent->isStatement(curr->condition)) { parent->setStatement(curr); } } @@ -1057,32 +1057,32 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { } Ref visitSelect(Select *curr) { if (isStatement(curr)) { - ScopedTemp tempCondition(i32, parent); - GetLocal fakeCondition; - fakeCondition.name = tempCondition.getName(); ScopedTemp tempIfTrue(curr->ifTrue->type, parent); GetLocal fakeLocalIfTrue; fakeLocalIfTrue.name = tempIfTrue.getName(); ScopedTemp tempIfFalse(curr->ifFalse->type, parent); GetLocal fakeLocalIfFalse; fakeLocalIfFalse.name = tempIfFalse.getName(); + ScopedTemp tempCondition(i32, parent); + GetLocal fakeCondition; + fakeCondition.name = tempCondition.getName(); Select fakeSelect = *curr; - fakeSelect.condition = &fakeCondition; fakeSelect.ifTrue = &fakeLocalIfTrue; fakeSelect.ifFalse = &fakeLocalIfFalse; - Ref ret = blockify(visitAndAssign(curr->condition, tempCondition)); - flattenAppend(ret, visitAndAssign(curr->ifTrue, tempIfTrue)); + fakeSelect.condition = &fakeCondition; + Ref ret = blockify(visitAndAssign(curr->ifTrue, tempIfTrue)); flattenAppend(ret, visitAndAssign(curr->ifFalse, tempIfFalse)); + flattenAppend(ret, visitAndAssign(curr->condition, tempCondition)); flattenAppend(ret, visitAndAssign(&fakeSelect, result)); return ret; } // normal select - Ref condition = visit(curr->condition, EXPRESSION_RESULT); Ref ifTrue = visit(curr->ifTrue, EXPRESSION_RESULT); Ref ifFalse = visit(curr->ifFalse, EXPRESSION_RESULT); - ScopedTemp tempCondition(i32, parent), - tempIfTrue(curr->type, parent), - tempIfFalse(curr->type, parent); + Ref condition = visit(curr->condition, EXPRESSION_RESULT); + ScopedTemp tempIfTrue(curr->type, parent), + tempIfFalse(curr->type, parent), + tempCondition(i32, parent); return ValueBuilder::makeSeq( ValueBuilder::makeAssign(tempCondition.getAstName(), condition), -- cgit v1.2.3