Skip to content

Commit 693f322

Browse files
committed
add optimized conditions for dereferenceability check
1 parent c75c728 commit 693f322

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ir/pointer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,18 @@ Pointer::isDereferenceable(const expr &bytes0, uint64_t align,
574574
p.getOffsetSizet().uge(block_sz).isTrue()) {
575575
cond = false;
576576
} else {
577-
// check that the offset is within bounds and that arith doesn't overflow
578-
cond = (offset + bytes_off).sextOrTrunc(block_sz.bits()).ule(block_sz);
579-
cond &= !offset.isNegative();
580-
if (!block_sz.isNegative().isFalse()) // implied if block_sz >= 0
581-
cond &= offset.add_no_soverflow(bytes_off);
582-
577+
// optimized conditions that are equivalent to the condition below
578+
if (block_sz.isConst() && bytes.isConst()) {
579+
cond = offset.ule(block_sz - bytes_off);
580+
} else if (bits_for_offset > bits_size_t && bytes.isOne()) {
581+
cond = offset.ult(block_sz);
582+
} else {
583+
// check that the offset is within bounds and that arith doesn't overflow
584+
cond = (offset + bytes_off).sextOrTrunc(block_sz.bits()).ule(block_sz);
585+
cond &= !offset.isNegative();
586+
if (!block_sz.isNegative().isFalse()) // implied if block_sz >= 0
587+
cond &= offset.add_no_soverflow(bytes_off);
588+
}
583589
cond &= block_constraints(p);
584590
}
585591
return cond;

0 commit comments

Comments
 (0)