Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yklua while loop fixes #1466

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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