memory: enable constant folding of get_address of conditional null ptrs
MODIFY
ir/memory.cpp
ir/memory.cpp
@@ -230,19 +230,19 @@ expr Pointer::get_value(const char *name, const FunctionExpr &local_fn,
expr Pointer::get_address(bool simplify) const {
assert(observes_addresses());
- expr offset = get_offset();
+ auto bid = get_short_bid();
+ auto zero = expr::mkUInt(0, bits_for_offset - 1);
// fast path for null ptrs
- if (simplify && (get_bid() == 0).isTrue())
- return offset;
+ auto non_local
+ = simplify && bid.isZero() ? zero : expr::mkUF("blk_addr", { bid }, zero);
- auto bid = get_short_bid();
// Local block area is the upper half of the memory
// Non-local block area is the lower half
- auto retty = expr::mkUInt(0, bits_for_offset - 1);
- return offset + expr::mkIf(is_local(),
+ return get_offset() +
+ expr::mkIf(is_local(),
expr::mkUInt(1, 1).concat(m.local_blk_addr(bid)),
- expr::mkUInt(0, 1).concat(expr::mkUF("blk_addr", { bid }, retty)));
+ expr::mkUInt(0, 1).concat(non_local));
}
expr Pointer::block_size() const {

memory: enable constant folding of get_address of conditional null ptrs