Skip to content

Commit

Permalink
Merge pull request #1466 from vext01/yklua-while-fixes
Browse files Browse the repository at this point in the history
Yklua while loop fixes
  • Loading branch information
ltratt authored Nov 18, 2024
2 parents f081d90 + 9ba3d0a commit 9530f86
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/yk-config
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ handle_arg() {
OUTPUT="${OUTPUT} -fyk-noinline-funcs-with-loops"
# Don't optimise functions by changing their calling convention.
OUTPUT="${OUTPUT} -mllvm -yk-dont-opt-func-abi"
# Ensure any jump threading pass that may run at pre-link time
# doesn't interfere with control points that will be added at
# link-time (the functionalities are guarded by the same flag).
OUTPUT="${OUTPUT} -mllvm -yk-patch-control-point"
;;
--cppflags)
# Path to yk.h
Expand Down
33 changes: 32 additions & 1 deletion ykrt/src/compile/jitc_yk/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,13 @@ impl Opt {
let Const::Int(_, v) = self.m.const_(cidx) else {
panic!()
};
// DynPtrAdd indices are signed, so we have to be careful to interpret the
// constant as such.
let v = *v as i64;
// LLVM IR allows `off` to be an `i64` but our IR currently allows only an
// `i32`. On that basis, we can hit our limits before the program has
// itself hit UB, at which point we can't go any further.
let off = i32::try_from(*v)
let off = i32::try_from(v)
.map_err(|_| ())
.and_then(|v| v.checked_mul(i32::from(x.elem_size())).ok_or(()))
.map_err(|_| {
Expand Down Expand Up @@ -1000,6 +1003,34 @@ mod test {
);
}

#[test]
fn opt_dynptradd_const() {
Module::assert_ir_transform_eq(
"
entry:
%0: ptr = load_ti 0
%1: ptr = dyn_ptr_add %0, 2i64, 8
black_box %1
%3: ptr = dyn_ptr_add %0, -1i64, 8
black_box %3
%5: ptr = dyn_ptr_add %0, -8i64, 16
black_box %5
",
|m| opt(m).unwrap(),
"
...
entry:
%0: ptr = load_ti...
%1: ptr = ptr_add %0, 16
black_box %1
%3: ptr = ptr_add %0, -8
black_box %3
%5: ptr = ptr_add %0, -128
black_box %5
",
);
}

#[test]
fn opt_guard_dup() {
Module::assert_ir_transform_eq(
Expand Down

0 comments on commit 9530f86

Please sign in to comment.