[llvm-commits] PATCH: Make 'trunc i8 %x to i1' canonical rather than 'icmp ne i8 (and i8 %x, 1), 0'

Chandler Carruth chandlerc at gmail.com
Wed Mar 28 03:37:16 PDT 2012

Currently, when converting an i8 loaded value to an i1 IR value, the
canonical pattern is:

%x.1 = and i8 %x, 1
%x.2 = icmp ne i8 %x, 0

This seems really cumbersome. The natural way to represent this is:

%x.2 = trunc i8 %x to i1

But for some reason instcombine canonicalizes it to the first pattern. I
feel like the second pattern is easier to reason about, easier to match in
further peep-hole optimizations, easier to fold with surrounding zext
operations, and easier to teach codegen to be clever about and eliminate
altogether given range metadata. Thoughts? I've attached the trivial change
to the code, but the real question is: do we want to do this? Why or why

At the very least, it'll make opt IR smaller. ;]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120328/706a796b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: canon-trunc-i1.diff
Type: text/x-patch
Size: 866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120328/706a796b/attachment.bin>

More information about the llvm-commits mailing list