Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float compare instruction merging #185

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jit/ByteCodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ static void createInstructionList(JITCompiler* compiler, ModuleFunction* functio
case ByteCode::F32X4ExtractLaneOpcode:
case ByteCode::F64X2ExtractLaneOpcode: {
SIMDExtractLane* extractLane = reinterpret_cast<SIMDExtractLane*>(byteCode);
Instruction* instr = compiler->append(byteCode, Instruction::ExtractLaneSIMD, opcode, 2, 0);
Instruction* instr = compiler->append(byteCode, Instruction::ExtractLaneSIMD, opcode, 1, 1);

Operand* operands = instr->operands();
operands[0].item = nullptr;
Expand Down
48 changes: 26 additions & 22 deletions src/jit/FloatMathInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,34 +438,38 @@ static bool emitFloatCompare(sljit_compiler* compiler, Instruction* instr)
RELEASE_ASSERT_NOT_REACHED();
}

Instruction* nextInstr = instr->next()->asInstruction();
Instruction* nextInstr = nullptr;
bool isSelect = false;

ASSERT(nextInstr != nullptr);
ASSERT(instr->next() != nullptr);

switch (nextInstr->opcode()) {
case ByteCode::JumpIfTrueOpcode:
case ByteCode::JumpIfFalseOpcode:
if (nextInstr->getParam(0)->item == instr) {
if (nextInstr->opcode() == ByteCode::JumpIfFalseOpcode) {
type ^= 0x1;
}
if (instr->next()->isInstruction()) {
nextInstr = instr->next()->asInstruction();

type |= (opcode & SLJIT_32);
switch (nextInstr->opcode()) {
case ByteCode::JumpIfTrueOpcode:
case ByteCode::JumpIfFalseOpcode:
if (nextInstr->getParam(0)->item == instr) {
if (nextInstr->opcode() == ByteCode::JumpIfFalseOpcode) {
type ^= 0x1;
}

sljit_jump* jump = sljit_emit_fcmp(compiler, type, params[0].arg, params[0].argw,
params[1].arg, params[1].argw);
nextInstr->asExtended()->value().targetLabel->jumpFrom(jump);
return true;
}
break;
case ByteCode::SelectOpcode:
if (nextInstr->getParam(2)->item == instr) {
isSelect = true;
type |= (opcode & SLJIT_32);

sljit_jump* jump = sljit_emit_fcmp(compiler, type, params[0].arg, params[0].argw,
params[1].arg, params[1].argw);
nextInstr->asExtended()->value().targetLabel->jumpFrom(jump);
return true;
}
break;
case ByteCode::SelectOpcode:
if (nextInstr->getParam(2)->item == instr) {
isSelect = true;
}
break;
default:
break;
}
break;
default:
break;
}

sljit_emit_fop1(compiler, opcode, params[0].arg, params[0].argw,
Expand Down
41 changes: 40 additions & 1 deletion test/basic/br.wast
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@
))
i32.const 200
)
(func (export "br_if_cmp")(param i32 i32 i64 f32 f64)(result i32 i32 i32 i32)
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 1
i32.const 100
i32.eq
end
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 2
i64.const 100
i64.eq
end
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 3
f32.const 100.0
f32.eq
end
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 4
f64.const 100.0
f64.eq
end
)
)

(assert_return (invoke "br0") (i32.const 1)(i32.const 2)(i32.const 3))
Expand All @@ -41,4 +79,5 @@
(assert_return (invoke "check") (i32.const 107))
(assert_return (invoke "br0_1"(i32.const 1))(i32.const 100))
(assert_return (invoke "br0_1"(i32.const 0))(i32.const 200))

(assert_return (invoke "br_if_cmp"(i32.const 0)(i32.const 100)(i64.const 100)(f32.const 100.0)(f64.const 100.0))
(i32.const 1)(i32.const 1)(i32.const 1)(i32.const 1))