@@ -638,7 +638,6 @@ impl Insn {
638
638
// NewHash's operands may be hashed and compared for equality, which could have
639
639
// side-effects.
640
640
Insn :: NewHash { elements, .. } => elements. len ( ) > 0 ,
641
- Insn :: NewRange { .. } => false ,
642
641
Insn :: ArrayDup { .. } => false ,
643
642
Insn :: HashDup { .. } => false ,
644
643
Insn :: Test { .. } => false ,
@@ -660,6 +659,9 @@ impl Insn {
660
659
Insn :: GetLocal { .. } => false ,
661
660
Insn :: IsNil { .. } => false ,
662
661
Insn :: CCall { elidable, .. } => !elidable,
662
+ // TODO: NewRange is effects free if we can prove the two ends to be Fixnum,
663
+ // but we don't have type information here in `impl Insn`. See rb_range_new().
664
+ Insn :: NewRange { .. } => true ,
663
665
_ => true ,
664
666
}
665
667
}
@@ -6198,6 +6200,29 @@ mod opt_tests {
6198
6200
"# ] ] ) ;
6199
6201
}
6200
6202
6203
+ #[ test]
6204
+ fn test_do_not_eliminate_new_range_non_fixnum ( ) {
6205
+ eval ( "
6206
+ def test()
6207
+ _ = (-'a'..'b')
6208
+ 0
6209
+ end
6210
+ test; test
6211
+ " ) ;
6212
+ assert_optimized_method_hir ( "test" , expect ! [ [ r#"
6213
+ fn test@<compiled>:3:
6214
+ bb0(v0:BasicObject):
6215
+ v1:NilClass = Const Value(nil)
6216
+ v4:StringExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
6217
+ PatchPoint BOPRedefined(STRING_REDEFINED_OP_FLAG, BOP_UMINUS)
6218
+ v6:StringExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
6219
+ v8:StringExact = StringCopy v6
6220
+ v10:RangeExact = NewRange v4 NewRangeInclusive v8
6221
+ v11:Fixnum[0] = Const Value(0)
6222
+ Return v11
6223
+ "# ] ] ) ;
6224
+ }
6225
+
6201
6226
#[ test]
6202
6227
fn test_eliminate_new_array_with_elements ( ) {
6203
6228
eval ( "
0 commit comments