Skip to content

Commit 573fe02

Browse files
committed
Fold unnecessary TO_BOOL
1 parent a7272a1 commit 573fe02

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

crates/codegen/src/ir.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,15 @@ impl CodeInfo {
693693
None
694694
}
695695
}
696+
(Instruction::LoadConst { consti }, Instruction::ToBool) => {
697+
let consti = consti.get(curr.arg);
698+
let constant = &self.metadata.consts[consti as usize];
699+
if let ConstantData::Boolean { .. } = constant {
700+
Some((curr_instr, OpArg::from(consti)))
701+
} else {
702+
None
703+
}
704+
}
696705
(Instruction::LoadConst { consti }, Instruction::UnaryNot) => {
697706
let constant = &self.metadata.consts[consti.get(curr.arg) as usize];
698707
match constant {

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__const_bool_not_op.snap

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)