ensure fn ret ptrs & ptr args cant alias with byval arguments
MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -955,6 +955,10 @@ void Memory::AliasSet::setMayAliasUpTo(bool local, unsigned limit) {
}
}
+void Memory::AliasSet::setNoAlias(bool islocal, unsigned bid) {
+ (islocal ? local : non_local)[bid] = false;
+}
+
void Memory::AliasSet::intersectWith(const AliasSet &other) {
auto intersect = [](auto &a, const auto &b) {
auto I2 = b.begin();
@@ -1569,6 +1573,11 @@ expr Memory::mkInput(const char *name, const ParamAttrs &attrs) {
AliasSet alias(*this);
alias.setMayAliasUpTo(false, max_bid);
+
+ for (auto byval_bid : byval_blks) {
+ state->addAxiom(bid != byval_bid);
+ alias.setNoAlias(false, byval_bid);
+ }
ptr_alias.emplace(p.getBid(), move(alias));
return p.release();
@@ -1622,11 +1631,16 @@ Memory::mkFnRet(const char *name, const vector<PtrInput> &ptr_inputs) {
}
unsigned max_nonlocal_bid = nextNonlocalPtr();
+ expr nonlocal = bid.ule(max_nonlocal_bid);
auto alias = escaped_local_blks;
alias.setMayAliasUpTo(false, max_nonlocal_bid);
+
+ for (auto byval_bid : byval_blks) {
+ nonlocal &= bid != byval_bid;
+ alias.setNoAlias(false, byval_bid);
+ }
ptr_alias.emplace(p.getBid(), move(alias));
- expr nonlocal = bid.ule(max_nonlocal_bid);
state->addAxiom(expr::mkIf(p.isLocal(), expr::mk_or(local), nonlocal));
return { p.release(), move(var) };
}

MODIFY
ir/memory.h
ir/memory.h
@@ -216,6 +216,7 @@ class Memory {
void setMayAlias(bool local, unsigned bid);
void setMayAliasUpTo(bool local, unsigned limit); // [0, limit]
+ void setNoAlias(bool local, unsigned bid);
void intersectWith(const AliasSet &other);
void unionWith(const AliasSet &other);

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -558,6 +558,7 @@ static void calculateAndInitConstants(Transform &t) {
uint64_t max_gep_src = 0, max_gep_tgt = 0;
uint64_t max_alloc_size = 0;
uint64_t max_access_size = 0;
+ uint64_t min_global_size = UINT64_MAX;
bool nullptr_is_used = false;
has_int2ptr = false;
@@ -595,7 +596,12 @@ static void calculateAndInitConstants(Transform &t) {
}
if (i && i->hasAttribute(ParamAttrs::ByVal)) {
does_mem_access = true;
- max_access_size = max(max_access_size, i->getAttributes().blockSize);
+ auto sz = i->getAttributes().blockSize;
+ max_access_size = max(max_access_size, sz);
+ min_global_size = min_global_size != UINT64_MAX
+ ? gcd(sz, min_global_size)
+ : sz;
+ min_global_size = gcd(min_global_size, i->getAttributes().align);
}
}
@@ -670,7 +676,6 @@ static void calculateAndInitConstants(Transform &t) {
unsigned num_locals = max(num_locals_src, num_locals_tgt);
- uint64_t min_global_size = UINT64_MAX;
for (auto glbs : { &globals_src, &globals_tgt }) {
for (auto &glb : *glbs) {
auto sz = max(glb->size(), (uint64_t)1u);

ensure fn ret ptrs & ptr args cant alias with byval arguments