Skip to content

Commit 8514166

Browse files
committed
ZJIT: Adjust Type API for checking signedness
1 parent be783db commit 8514166

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

zjit/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5296,7 +5296,7 @@ impl Function {
52965296
}
52975297
Insn::AdjustBounds { index, .. } => {
52985298
// If index is known nonnegative, then we don't need to adjust bounds.
5299-
if self.type_of(index).cint64_value().filter(|&i| i >= 0).is_some() {
5299+
if self.type_of(index).known_nonnegative() {
53005300
self.make_equal_to(insn_id, index);
53015301
// Don't bother re-inferring the type of index; we already know it.
53025302
continue;

zjit/src/hir_type/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,19 @@ impl Type {
411411
}
412412
}
413413

414+
fn int_spec_signed(&self) -> Option<i64> {
415+
assert!(self.is_subtype(types::CSigned), "int_spec_signed() only makes sense for signed integer types");
416+
match self.spec {
417+
Specialization::Int(val) => Some(val as i64),
418+
_ => None,
419+
}
420+
}
421+
422+
pub fn known_nonnegative(&self) -> bool {
423+
assert!(self.is_subtype(types::CSigned), "nonnegative() only makes sense for signed integer types");
424+
self.int_spec_signed().map_or(false, |val| val >= 0)
425+
}
426+
414427
/// Return true if the Type has object specialization and false otherwise.
415428
pub fn ruby_object_known(&self) -> bool {
416429
matches!(self.spec, Specialization::Object(_))

0 commit comments

Comments
 (0)