This is an archive of the discontinued LLVM Phabricator instance.

Refactor ValueTracking isDereferenceableAndAlignedPointer
AbandonedPublic

Authored by apilipenko on Jan 12 2016, 9:35 AM.

Details

Reviewers
reames
hfinkel
Summary

Current implementation of isDereferenceableAndAlignedPointer is messy. It tries to handle sized/non-sized types, looking through casts/relocations and inherent value dereferenceability properties in a single recursive function. Recent addition of alignment handling and context-sensitive non-null analysis made it even worse. This patch is an attempt to clean it up.

Inherent value dereferenceability properties are now handled in Value class:

  • Value::isDereferenceablePointer
  • Value::getDereferenceableBytes

The code which tracks dereferencability over a chain of values remains in ValueTracking. isDereferenceableAndAlignedPointer is no longer recursive. Instead it uses helper functions to strip all the casts/compute a base pointer and offset.

Overall structure of this code is as follows:

  • Try to determine if a value is dereferenceable without dealing with type sizes. Strip type safe transformations only: address space casts, global aliases, GC relocations. If the resulting pointer is fully dereferenceable we are done. It will handle derferencability of opaque types.
  • If the accessed type is sized try to decompose the value to a base pointer and an offset. Check if the accessed value lies within dereferenceable portion of the base pointer.

Diff Detail

Event Timeline

apilipenko updated this revision to Diff 44646.Jan 12 2016, 9:35 AM
apilipenko retitled this revision from to Refactor ValueTracking isDereferenceableAndAlignedPointer.
apilipenko updated this object.
apilipenko added reviewers: hfinkel, reames.
apilipenko updated this object.
apilipenko added a subscriber: llvm-commits.
apilipenko updated this revision to Diff 44837.Jan 14 2016, 1:24 AM

Rework stripForDereferenceable, stripAndAccumulateOffsetForDereferenceable to use standard Value::stripPointerCasts and GetPointerBaseWithConstantOffset functions. Now it's clear that the only reasons for these helpers is to look through gc relocations. I'm not sure that this is the right way to handle relocations though. But the current state is functional equivalent to what we had before the refactoring. May be we should update InstCombine to propagate dereferenceability through relocations instead of relying on looking through them (see D16143).

apilipenko planned changes to this revision.Jan 15 2016, 8:49 AM

I'm going to split this change into a set of smaller ones.

apilipenko abandoned this revision.Feb 19 2016, 2:20 AM