[PATCH] D22793: IR: Introduce inbounds attribute on getelementptr indices.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 27 18:29:19 PDT 2016


pete added a subscriber: pete.

================
Comment at: include/llvm/IR/Operator.h:382
@@ -381,1 +381,3 @@
   }
+  /// Returns the offset of the index with an inrange attachment, or None if
+  /// none.
----------------
Sorry to come late to this one...

My read on this implies that inrange on the start of a GEP would be equivalent to inbounds today.  Is that the case?

Assuming it is, the inrange is strictly a more accurate version of inbounds, and we should only have inrange.  Put another way, keep the name inbounds, but allow it to be applied to any single type in the GEP.

So that would make all of these equivalent in terms of AA, and all of these alias each other:
  %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2
  %arrayidx = getelementptr %struct.ST, %struct.ST* %s, inbounds i64 1, i32 2
  %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, inbounds i32 2

But these won't alias because the inbounds applies to an index with a different value:
  %arrayidx = getelementptr %struct.ST, %struct.ST* %s, inbounds i64 0, i32 2
  %arrayidx = getelementptr %struct.ST, %struct.ST* %s, inbounds i64 1, i32 2

And these will alias because one has inbounds and the other doesn't:
  %arrayidx = getelementptr %struct.ST, %struct.ST* %s, i64 0, i32 2
  %arrayidx = getelementptr %struct.ST, %struct.ST* %s, inbounds i64 1, i32 2


https://reviews.llvm.org/D22793





More information about the llvm-commits mailing list