Skip to content

Commit

Permalink
asm mode: allow loads to be widened up to 'align' size
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Dec 13, 2023
1 parent 0670157 commit 030007d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tools/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pair<const Instr*, unique_ptr<Instr>>> to_add;
for (auto &bb : src.getBBs()) {
for (auto &i : bb->instrs()) {
if (auto *load = dynamic_cast<const Load*>(&i)) {
auto align = load->getAlign();
if (align != 1) {
static IntType i64("i64", 64);
auto bytes = make_unique<IntConst>(i64, align);
to_add.emplace_back(load, make_unique<Assume>(
vector<Value*>{&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);

Expand Down

0 comments on commit 030007d

Please sign in to comment.