Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Preserve nonnull metadata on Loads through SROA & mem2reg #90

Merged

Commits on Jul 1, 2017

  1. Preserve nonnull metadata on Loads through SROA & mem2reg.

    Summary:
    https://llvm.org/bugs/show_bug.cgi?id=31142 :
    
    SROA was dropping the nonnull metadata on loads from allocas that got optimized out. This patch simply preserves nonnull metadata on loads through SROA and mem2reg.
    
    Reviewers: chandlerc, efriedma
    
    Reviewed By: efriedma
    
    Subscribers: hfinkel, spatel, efriedma, arielb1, davide, llvm-commits
    
    Differential Revision: https://reviews.llvm.org/D27114
    
    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298540 91177308-0d34-0410-b5e6-96231b3b80d8
    luqmana authored and arielb1 committed Jul 1, 2017
    Configuration menu
    Copy the full SHA
    7d1c3d4 View commit details
    Browse the repository at this point in the history
  2. [InstCombine] Factor the logic for propagating !nonnull and !range

    metadata out of InstCombine and into helpers.
    
    NFC, this just exposes the logic used by InstCombine when propagating
    metadata from one load instruction to another. The plan is to use this
    in SROA to address PR32902.
    
    If anyone has better ideas about how to factor this or name variables,
    I'm all ears, but this seemed like a pretty good start and lets us make
    progress on the PR.
    
    This is based on a patch by Ariel Ben-Yehuda (D34285).
    
    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306267 91177308-0d34-0410-b5e6-96231b3b80d8
    chandlerc authored and arielb1 committed Jul 1, 2017
    Configuration menu
    Copy the full SHA
    98de0be View commit details
    Browse the repository at this point in the history
  3. [SROA] Clean up a test case a bit prior to adding more testing for

    nonnull as part of fixing PR32902.
    
    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306353 91177308-0d34-0410-b5e6-96231b3b80d8
    chandlerc authored and arielb1 committed Jul 1, 2017
    Configuration menu
    Copy the full SHA
    d45f4ff View commit details
    Browse the repository at this point in the history
  4. [SROA] Further test cleanup and add a test for the actual propagation of

    the nonnull attribute distinct from rewriting it into an assume.
    
    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306358 91177308-0d34-0410-b5e6-96231b3b80d8
    chandlerc authored and arielb1 committed Jul 1, 2017
    Configuration menu
    Copy the full SHA
    70e9bbd View commit details
    Browse the repository at this point in the history
  5. [SROA] Fix PR32902 by more carefully propagating !nonnull metadata.

    This is based heavily on the work done ni D34285. I mostly wanted to do
    test cleanup for the author to save them some time, but I had a really
    hard time understanding why it was so hard to write better test cases
    for these issues.
    
    The problem is that because SROA does a second rewrite of the loads and
    because we *don't* propagate !nonnull for non-pointer loads, we first
    introduced invalid !nonnull metadata and then stripped it back off just
    in time to avoid most ways of this PR manifesting. Moving to the more
    careful utility only fixes this by changing the predicate to look at the
    new load's type rather than the target type. However, that *does* fix
    the bug, and the utility is much nicer including adding range metadata
    to model the nonnull property after a conversion to an integer.
    
    However, we have bigger problems because we don't actually propagate
    *range* metadata, and the utility to do this extracted from instcombine
    isn't really in good shape to do this currently. It *only* handles the
    case of copying range metadata from an integer load to a pointer load.
    It doesn't even handle the trivial cases of propagating from one integer
    load to another when they are the same width! This utility will need to
    be beefed up prior to using in this location to get the metadata to
    fully survive.
    
    And even then, we need to go and teach things to turn the range metadata
    into an assume the way we do with nonnull so that when we *promote* an
    integer we don't lose the information.
    
    All of this will require a new test case that looks kind-of like
    `preserve-nonnull.ll` does here but focuses on range metadata. It will
    also likely require more testing because it needs to correctly handle
    changes to the integer width, especially as SROA actively tries to
    change the integer width!
    
    Last but not least, I'm a little worried about hooking the range
    metadata up here because the instcombine logic for converting from
    a range metadata *to* a nonnull metadata node seems broken in the face
    of non-zero address spaces where null is not mapped to the integer `0`.
    So that probably needs to get fixed with test cases both in SROA and in
    instcombine to cover it.
    
    But this *does* extract the core PR fix from D34285 of preventing the
    !nonnull metadata from being propagated in a broken state just long
    enough to feed into promotion and crash value tracking.
    
    On D34285 there is some discussion of zero-extend handling because it
    isn't necessary. First, the new load size covers all of the non-undef
    (ie, possibly initialized) bits. This may even extend past the original
    alloca if loading those bits could produce valid data. The only way its
    valid for us to zero-extend an integer load in SROA is if the original
    code had a zero extend or those bits were undef. And we get to assume
    things like undef *never* satifies nonnull, so non undef bits can
    participate here. No need to special case the zero-extend handling, it
    just falls out correctly.
    
    The original credit goes to Ariel Ben-Yehuda! I'm mostly landing this to
    save a few rounds of trivial edits fixing style issues and test case
    formulation.
    
    Differental Revision: D34285
    
    git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306379 91177308-0d34-0410-b5e6-96231b3b80d8
    chandlerc authored and arielb1 committed Jul 1, 2017
    Configuration menu
    Copy the full SHA
    b514eb0 View commit details
    Browse the repository at this point in the history