Skip to content

Remove unreachable x64 lowerings for iadd_imm#4726

Merged
jameysharp merged 1 commit into
bytecodealliance:mainfrom
jameysharp:unreachable-lowering
Aug 16, 2022
Merged

Remove unreachable x64 lowerings for iadd_imm#4726
jameysharp merged 1 commit into
bytecodealliance:mainfrom
jameysharp:unreachable-lowering

Conversation

@jameysharp
Copy link
Copy Markdown
Contributor

All of the *_imm instructions are rewritten during legalization to an explicit iconst plus the general form of the operator, so backends never see them. Therefore these ISLE rules in the x64 backend can never match anything.

This came up in #4721 but is independent of that issue.

All of the `*_imm` instructions are rewritten during legalization to an
explicit `iconst` plus the general form of the operator, so backends
never see them. Therefore these ISLE rules in the x64 backend can never
match anything.
@jameysharp jameysharp requested a review from elliottt August 16, 2022 20:59
Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@elliottt
Copy link
Copy Markdown
Member

Just to close the loop, this is the legalization step that removes the _imm instructions:

InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}

@jameysharp jameysharp enabled auto-merge (squash) August 16, 2022 21:07
@jameysharp jameysharp merged commit c569e7b into bytecodealliance:main Aug 16, 2022
@jameysharp jameysharp deleted the unreachable-lowering branch August 17, 2022 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants