[llvm-commits] [patch] Use the range metadata in CodeGen

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Mar 29 20:22:14 PDT 2012


The attached patch changes the DAG builder to create a ExtLoad when
the range metadata indicates the loaded value is just 0 or 1. This
makes us codegen

define zeroext i1 @f(i8* %x) {
entry:
  %0 = load i8* %x, align 1, !range !0
  %tobool = trunc i8 %0 to i1
  ret i1 %tobool
}

to just

movb	(%rdi), %al

I was unable to generalize this to other ranges.

Currently the IL optimizers canonicalize the function to

define zeroext i1 @f(i8* %x) {
entry:
  %0 = load i8* %x, align 1, !range !0
  %tobool = icmp ne i8 %0, 0
  ret i1 %tobool
}

So the patch also adds a bit of pattern match to handle it. Another
option would be to convert the SetCC to a Truncate node, but it would
be strange to canonicalize one way in the IL and the other way in the
DAG. If  Chandler changes the canonical IL then we should probably
change this too.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dag.patch
Type: application/octet-stream
Size: 4863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120329/8447a8da/attachment.obj>


More information about the llvm-commits mailing list