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

Chris Lattner clattner at apple.com
Fri Mar 30 13:35:44 PDT 2012


On Mar 28, 2012, at 3:37 AM, Chandler Carruth wrote:
> 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 not?

This was added in r67635:

"Make instcombine always canonicalize trunc x to i1 into an icmp(x&1).  This 
exposes the AND to other instcombine xforms and is more of what the code
generator expects."

The 'trunc to i1' is not legal for any target, and that exposing it to the IR optimizer allows us to simplify and eliminate the and.

-Chris




More information about the llvm-commits mailing list