[PATCH] Remove unnecessary variable indexing into single-element arrays

Chandler Carruth chandlerc at gmail.com
Thu Feb 19 19:24:41 PST 2015


On Thu, Feb 19, 2015 at 6:58 PM, hfinkel at anl.gov <hfinkel at anl.gov> wrote:

> Comment at:
> lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:592-595
> @@ +591,6 @@
> +
> +  // If there are more indices after the one we might replace with a
> zero, make
> +  // sure they're all non-negative. If any of them are negative, the
> overall
> +  // address being computed might be before the base address determined
> by the
> +  // first non-zero index.
> +  auto AllNonNegative = [&]() -> bool {
> ----------------
> chandlerc wrote:
> > Maybe too clever, but what do you think about bailing the first time you
> see a positive index as well since you're checking for inbounds? You could
> make the predicate "canBacktrackFromPastEnd" or some such. As soon as you
> see a potentially negative index return true, as soon as you see a
> definitely positive index, return false, if you exhaust the indices return
> false.
> I'm not sure that works. Even after a positive index, we could have a
> "larger" negative index, and we could still keep everthing inbounds.


Nope, inbounds says that all intermediate pointers must be inbounds. The
moment you go more than 1-past-the-end, even 1 byte more, boom.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150219/eeaedf54/attachment.html>


More information about the llvm-commits mailing list