Skip to content

Commit 2541d73

Browse files
committed
ZJIT: Parse opt_not into HIR
1 parent c984987 commit 2541d73

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

test/ruby/test_zjit.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ def test(x, y) = x | y
233233
RUBY
234234
end
235235

236+
def test_opt_not
237+
assert_compiles('[true, true, false]', <<~RUBY, insns: [:opt_not])
238+
def test(obj) = !obj
239+
return test(nil), test(false), test(0)
240+
RUBY
241+
end
242+
236243
def test_opt_ge
237244
assert_compiles '[false, true, true]', %q{
238245
def test(a, b) = a >= b

zjit/src/hir.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23492349
YARVINSN_opt_succ |
23502350
YARVINSN_opt_and |
23512351
YARVINSN_opt_or |
2352+
YARVINSN_opt_not |
23522353
YARVINSN_opt_send_without_block => {
23532354
let cd: *const rb_call_data = get_arg(pc, 0).as_ptr();
23542355
let call_info = unsafe { rb_get_call_data_ci(cd) };
@@ -3804,6 +3805,19 @@ mod tests {
38043805
Return v5
38053806
"#]]);
38063807
}
3808+
3809+
#[test]
3810+
fn opt_not() {
3811+
eval("
3812+
def test(x) = !x
3813+
");
3814+
assert_method_hir_with_opcode("test", YARVINSN_opt_not, expect![[r#"
3815+
fn test:
3816+
bb0(v0:BasicObject, v1:BasicObject):
3817+
v4:BasicObject = SendWithoutBlock v1, :!
3818+
Return v4
3819+
"#]]);
3820+
}
38073821
#[test]
38083822
fn test_branchnil() {
38093823
eval("

0 commit comments

Comments
 (0)