[llvm-commits] [patch][pr12251] Add a "range" metadata, use it to remove unnecessary ands
Rafael EspĂndola
rafael.espindola at gmail.com
Tue Mar 20 13:43:20 PDT 2012
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.
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm.patch
Type: text/x-patch
Size: 4753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120320/b49ab913/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang.patch
Type: text/x-patch
Size: 3077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120320/b49ab913/attachment-0001.bin>
More information about the llvm-commits
mailing list