[llvm-commits] [patch][pr12251] Add a "range" metadata, use it to remove unnecessary ands

Duncan Sands baldrick at free.fr
Tue Mar 20 13:48:10 PDT 2012


Hi Rafael, some quick comments since I don't have time to read the
patch right now.

> The attached patches add a range metadata to llvm and change clang to
> produce it. I think it covers all the use cases in comment 7 on
> pr12251.

Are any ranges actually useful except "this many top bits are known zero", or
"this many top bits are equal to the sign bit"?  [You might think that Ada is
a language that would find ranges useful, since you can define types with a
given range, but in fact given Ada semantics I'm pretty sure this is actually
useless for Ada].

Also, what does a range mean?  Are you using signed comparison or unsigned?

Ciao, Duncan.

>
> With these changes, we compile
>
> bool foo(bool *x) {
>    return *x;
> }
>
> to
>
> define zeroext i1 @_Z3fooPb(i8* nocapture %x) nounwind uwtable
> readonly optsize {
> entry:
>    %0 = load i8* %x, align 1, !tbaa !0, !range !3
>    %tobool = icmp ne i8 %0, 0
>    ret i1 %tobool
> }
>
> Which is probably as good as it gets in the IL if we are going to load
> an i8 and return an i1. The generated assembly is
>
>
> 	cmpb	$0, (%rdi)
> 	setne	%al
> 	ret
>
> Not sure if it is faster, but unfortunately it is 2 bytes larger :-(
> It should be possible to improve codegen to take advantage of the
> metadata too, but I think the best solution is to just return an i8
> (i.e., implement
> http://nondot.org/sabre/LLVMNotes/ExtendedIntegerResults.txt).
>
> Other questions:
> * ) should clang produce this metadata at -O0?
> *) should it be documented in the language ref?
> *) should the verifier check it?
>
> Thanks,
> Rafael




More information about the llvm-commits mailing list