From 83c9f166da2bafb7c6a33475f9df7f60bf273d6c Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Thu, 19 Dec 2024 15:56:26 +0000 Subject: [PATCH] Add a C test for peeling. Previously it was impractical for us to write a test for peeling: limitations in the optimiser meant that you needed a complex set of things to go right for peeling to end up having visibly good effects. The previous commit to this has made it possible for us to write a small test that makes the effect of peeling obvious: in this case we are able to elide a guard in the body. --- tests/c/peel1.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/c/peel1.c diff --git a/tests/c/peel1.c b/tests/c/peel1.c new file mode 100644 index 000000000..9d6b10843 --- /dev/null +++ b/tests/c/peel1.c @@ -0,0 +1,52 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O2 +// Run-time: +// env-var: YKD_SERIALISE_COMPILATION=1 +// env-var: YKD_LOG_IR=jit-post-opt +// stderr: +// 0 1 +// --- Begin jit-post-opt --- +// ... +// guard true, ... +// ... +// guard true, ... +// header_end [1i32, ... +// ... +// body_start ... +// ... +// guard true, ... +// body_end [1i32, ... +// --- End jit-post-opt --- +// 1 1 +// 2 1 +// 3 1 +// 4 1 + +// Check that peeling works: a constant should be discovered by `header_end` +// that allows the body to have only 1 guard where the header must have 2. + +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + YkMT *mt = yk_mt_new(NULL); + yk_mt_hot_threshold_set(mt, 0); + YkLocation loc = yk_location_new(); + + int i = 0; + NOOPT_VAL(i); + for (; i < 5; i++) { + yk_mt_control_point(mt, &loc); + int y = yk_promote(argc); + + fprintf(stderr, "%d %d\n", i, y); + } + + yk_location_drop(loc); + yk_mt_shutdown(mt); + return (EXIT_SUCCESS); +}