[llvm-commits] [patch][pr12251] Use the range metadata in computeMaskedBits and add an optimization to InstructionSimplify.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Mar 23 19:56:50 PDT 2012


With the attached patch we compile

bool f(bool *x) {
  return *x;
}

to

define zeroext i1 @_Z1fPb(i8* nocapture %x) nounwind uwtable readonly {
entry:
  %0 = load i8* %x, align 1, !tbaa !0, !range !3
  %tobool = icmp ne i8 %0, 0
  ret i1 %tobool
}

Instead of

define zeroext i1 @_Z1fPb(i8* nocapture %x) nounwind uwtable readonly {
entry:
  %0 = load i8* %x, align 1, !tbaa !0
  %1 = and i8 %0, 1
  %tobool = icmp ne i8 %1, 0
  ret i1 %tobool
}

And the assembly changes from

	movb	(%rdi), %al
	andb	$1, %al
	ret

To

	cmpb	$0, (%rdi)
	setne	%al
	ret

Not sure if the assembly change is an improvement, so maybe this patch
should go in with a change to return i8, but I am sending it for
review first.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt.patch
Type: text/x-patch
Size: 4065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120323/7dcd9c42/attachment.bin>


More information about the llvm-commits mailing list