[llvm-commits] [patch][pr12251] Add range metadata to llvm. Make clang produce it.

Chris Lattner clattner at apple.com
Fri Mar 23 15:20:20 PDT 2012


On Mar 23, 2012, at 10:40 AM, Rafael EspĂ­ndola wrote:

>> OK, that's fair.  One good thing about [A, B) is that someone working with
>> i32
>> who wants to represent [0, 2^32-1] will say to themselves: "oh no, I need to
>> output [0, 2^32) but I can't represent that in 32 bits", and then realize
>> that
>> they were being silly wanting to output this range in the first place :)
> 
> That is true, that was my first reaction to using half open ranges :-)
> Nick (on IRC) also mentioned that he prefers half open ranges, so this
> new pair of patches uses it.

+<div>
+<p><tt>range</tt> metadata may be attached only to loads of integer types. It

Just *think* of the precedent this sets for FP types ;-)

+<ul>
+   <li>The type must match the type loaded by the instruction.</li>
+   <li>The pair <tt>a,b</tt> represents the range <tt>[a,b)</tt>.</li>
+   <li>The range is allowed to wrap.</li>
+   <li>The range should not represent the full or empty set. That is,
+       <tt>a!=b</tt>. </li>

Also, "a" and "b" are required to be ConstantInts.




+<p>Examples:</p>
+<div class="doc_code">
+<pre>
+metadata !{ i8 0, i8 2 } ; Can only be 0 or 1
+metadata !{ i8 255, i8 2 } ; Can only be 255 (-1), 0 or 1

Please make this be more fully formed so that people can understand it, something like:

...
  %x = load i8* %P1, !range !0  ; Can only be 0 or 1
  %y = load i8* %P2, !range !1  ; Can only be 255 (-1), 0 or 1

!0 = metadata !{ i8 0, i8 2 } 
!1 = metadata !{ i8 255, i8 2 }
...



Incidentally, your code in the verifier makes it look like you actually require a list of pairs, e.g. !{ !{ i8 0, i8 2 } }   or   !{ !{ i8 0, i8 2 }, !{ i8 4, i8 7 } }.  Is there any reason not to just use a flattened list?  Particularly given how the asmprinter prints out nested MDNodes, this would be a lot easier to read and reason about.


The verifier doesn't seem to check that LI.getType() matches the Low/High types.

Otherwise, looks great to me!

-Chris



More information about the llvm-commits mailing list