From 030007dc25e6792f9cfee9b413dd990d04aa316e Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Wed, 13 Dec 2023 21:23:45 +0000 Subject: [PATCH] asm mode: allow loads to be widened up to 'align' size --- tools/transform.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/transform.cpp b/tools/transform.cpp index 769eb119c..ba837c371 100644 --- a/tools/transform.cpp +++ b/tools/transform.cpp @@ -1618,9 +1618,33 @@ static void optimize_ptrcmp(Function &f) { } void Transform::preprocess() { - if (config::tgt_is_asm) + if (config::tgt_is_asm) { tgt.getFnAttrs().set(FnAttrs::Asm); + // all memory blocks are considered to have a size multiple of alignment + // since asm memory accesses won't trap as it won't cross the page boundary + vector>> to_add; + for (auto &bb : src.getBBs()) { + for (auto &i : bb->instrs()) { + if (auto *load = dynamic_cast(&i)) { + auto align = load->getAlign(); + if (align != 1) { + static IntType i64("i64", 64); + auto bytes = make_unique(i64, align); + to_add.emplace_back(load, make_unique( + vector{&load->getPtr(), bytes.get()}, + Assume::Dereferenceable)); + src.addConstant(std::move(bytes)); + } + } + } + for (auto &[i, assume] : to_add) { + bb->addInstrAt(std::move(assume), i, false); + } + to_add.clear(); + } + } + remove_unreachable_bbs(src); remove_unreachable_bbs(tgt);