diff options
author | Max Bernstein <[email protected]> | 2025-04-24 12:40:53 -0400 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2025-04-24 11:33:11 -0700 |
commit | 71166f60d95f0d78de5f151205ef6060de5e054e (patch) | |
tree | 1cd2f1def9fb663564711e1e2129ba6f230d9b7e | |
parent | c2677f4d0ba7ef3741020c754a498e4582cfe708 (diff) |
Add tests
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13162
-rw-r--r-- | zjit/src/hir.rs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index 9758731460..369ee0a137 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -2892,6 +2892,109 @@ mod opt_tests { } #[test] + fn test_optimize_send_into_fixnum_add_both_profiled() { + eval(" + def test(a, b) = a + b + test(1,2); test(3,4) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_PLUS) + v7:Fixnum = GuardType v0, Fixnum + v8:Fixnum = GuardType v1, Fixnum + v9:Fixnum = FixnumAdd v7, v8 + Return v9 + "#]]); + } + + #[test] + fn test_optimize_send_into_fixnum_add_left_profiled() { + eval(" + def test(a) = a + 1 + test(1); test(3) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject): + v2:Fixnum[1] = Const Value(1) + PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_PLUS) + v7:Fixnum = GuardType v0, Fixnum + v8:Fixnum = FixnumAdd v7, v2 + Return v8 + "#]]); + } + + #[test] + fn test_optimize_send_into_fixnum_add_right_profiled() { + eval(" + def test(a) = 1 + a + test(1); test(3) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject): + v2:Fixnum[1] = Const Value(1) + PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_PLUS) + v7:Fixnum = GuardType v0, Fixnum + v8:Fixnum = FixnumAdd v2, v7 + Return v8 + "#]]); + } + + #[test] + fn test_optimize_send_into_fixnum_lt_both_profiled() { + eval(" + def test(a, b) = a < b + test(1,2); test(3,4) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_LT) + v7:Fixnum = GuardType v0, Fixnum + v8:Fixnum = GuardType v1, Fixnum + v9:BoolExact = FixnumLt v7, v8 + Return v9 + "#]]); + } + + #[test] + fn test_optimize_send_into_fixnum_lt_left_profiled() { + eval(" + def test(a) = a < 1 + test(1); test(3) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject): + v2:Fixnum[1] = Const Value(1) + PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_LT) + v7:Fixnum = GuardType v0, Fixnum + v8:BoolExact = FixnumLt v7, v2 + Return v8 + "#]]); + } + + #[test] + fn test_optimize_send_into_fixnum_lt_right_profiled() { + eval(" + def test(a) = 1 < a + test(1); test(3) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject): + v2:Fixnum[1] = Const Value(1) + PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_LT) + v7:Fixnum = GuardType v0, Fixnum + v8:BoolExact = FixnumLt v2, v7 + Return v8 + "#]]); + } + + + #[test] fn test_eliminate_new_array() { eval(" def test() |