Skip to content

Commit 920df7a

Browse files
authored
Fix compile time regression for null ptr comparisons (#59259)
Fixes the compile time regression in #59134 (does not address the performance regression that should be tracked and bisected)
1 parent 7bbb213 commit 920df7a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/cgutils.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,17 +1601,30 @@ static void undef_var_error_ifnot(jl_codectx_t &ctx, Value *ok, jl_sym_t *name,
16011601
ctx.builder.SetInsertPoint(ifok);
16021602
}
16031603

1604+
1605+
static bool has_known_null_nullptr(Type *T)
1606+
{
1607+
if (auto PT = cast<PointerType>(T)) {
1608+
auto addrspace = PT->getAddressSpace();
1609+
if (addrspace == AddressSpace::Generic || (AddressSpace::FirstSpecial <= addrspace && addrspace <= AddressSpace::LastSpecial)) {
1610+
return true;
1611+
}
1612+
}
1613+
return false;
1614+
}
1615+
16041616
// ctx.builder.CreateIsNotNull(v) lowers incorrectly in non-standard
16051617
// address spaces where null is not zero
16061618
// TODO: adapt to https://github.com/llvm/llvm-project/pull/131557 once merged
16071619
static Value *null_pointer_cmp(jl_codectx_t &ctx, Value *v)
16081620
{
16091621
++EmittedNullchecks;
16101622
Type *T = v->getType();
1611-
return ctx.builder.CreateICmpNE(
1612-
v,
1613-
ctx.builder.CreateAddrSpaceCast(
1614-
Constant::getNullValue(ctx.builder.getPtrTy(0)), T));
1623+
if (has_known_null_nullptr(T))
1624+
return ctx.builder.CreateIsNotNull(v);
1625+
else
1626+
return ctx.builder.CreateICmpNE(v, ctx.builder.CreateAddrSpaceCast(
1627+
Constant::getNullValue(ctx.builder.getPtrTy(0)), T));
16151628
}
16161629

16171630

0 commit comments

Comments
 (0)