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

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Mar 29 18:34:06 PDT 2012


> Thoughts?
>
> I'm entirely convinced whether this is the correct approach, so I'd
> appreciate thoughts of others. There are 3 or 4 test failures I'm mopping up
> where we were expecting the and+icmp pair, but none of them seem interesting
> or noteworthy. Just shorter. ;]

Using trunc does make the existing CodeGen logic happier. The simple
attached patch makes

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

codegen to

	movb	(%rdi), %al
	ret

It should be possible to make it handle

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

But it would require some additions to the dag combiner.

> -Chandler

Cheers,
Rafael



More information about the llvm-commits mailing list