Skip to content
Merged
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
15 changes: 12 additions & 3 deletions cranelift/codegen/src/egraph/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,27 @@ impl Cost {
| Opcode::Ushr
| Opcode::Sshr => Cost::new(3, 0),

// "Expensive" arithmetic.
Opcode::Imul => Cost::new(10, 0),

// Everything else.
_ => {
// By default, be slightly more expensive than "simple"
// arithmetic.
let mut c = Cost::new(4, 0);

// And then get more expensive as the opcode does more side
// effects.
if op.can_trap() || op.other_side_effects() {
c = c + Cost::new(5, 0);
c = c + Cost::new(10, 0);
}
if op.can_load() {
c = c + Cost::new(10, 0);
c = c + Cost::new(20, 0);
}
if op.can_store() {
c = c + Cost::new(20, 0);
c = c + Cost::new(50, 0);
}

c
}
}
Expand Down