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

Hal Finkel hfinkel at anl.gov
Wed Mar 28 12:00:24 PDT 2012


On Wed, 28 Mar 2012 03:37:16 -0700
Chandler Carruth <chandlerc at gmail.com> 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?
> 
> At the very least, it'll make opt IR smaller. ;]

FWIW, the second form is also easier to vectorize.

 -Hal

-- 
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list