[PATCH] D96663: [InstCombine] Fold nonnull (select c,null,p) to nonnull p

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 21 19:03:59 PST 2021


aqjune added a comment.

In D96663#2577600 <https://reviews.llvm.org/D96663#2577600>, @spatel wrote:

> The code duplication suggests that we should have a common place for this logic (especially if it already exists in SimplifyCFG). 
> Could it be added to ValueTracking's isKnownNonZero() or wrap around that? 
> It might already be in there under isKnownNonNullFromDominatingCondition(), but we need to fix it up to deal with selects?

Hmm, as you said, adding the "assume((select cond, null, p) != null)" pattern to isKnownNonZeroFromAssume seems enough?
Compiling the Rust code snippet from pr48975 already creates llvm.assume: https://godbolt.org/z/8KxWKP
That being said, it might be a good idea to update `passingValueIsAlwaysUndefined` to check `CB->paramHasAttr(ArgIdx, Attribute::Dereferenceable)` as well because `dereferenceable` is quite common. `dereferenceable` implies `noundef`, so it is valid to assume that passing null to `nonnull dereferenceable` is UB. What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96663/new/

https://reviews.llvm.org/D96663



More information about the llvm-commits mailing list