I decided to pump some IR through the optimizers and was surprised to find
that we don't choose to canonicalize any of the following functions to the
other even though they are all roughly the same.
define i32 @f1(i32 %x, i32 %m) #0 {
entry:
%and = and i32 %m, 32896
%tobool = icmp ne i32 %and, 0
%cond = select i1 %tobool, i32 8, i32 0
%shr = lshr i32 %x, %cond
ret i32 %shr
}
; Function Attrs: nounwind readnone uwtable
define i32 @f2(i32 %x, i32 %m) #0 {
entry:
%and = and i32 %m, 32896
%tobool = icmp eq i32 %and, 0
%shr = lshr i32 %x, 8
%x.shr = select i1 %tobool, i32 %x, i32 %shr
ret i32 %x.shr
}
; Function Attrs: nounwind readnone uwtable
define i32 @f3(i32 %x, i32 %m) #0 {
entry:
%and = and i32 %m, 32896
%tobool = icmp ne i32 %and, 0
%conv = zext i1 %tobool to i32
%shl = shl nuw nsw i32 %conv, 3
%shr = lshr i32 %x, %shl
ret i32 %shr
}
attributes #0 = { nounwind readnone uwtable
"less-precise-fpmad"="false"
"no-frame-pointer-elim"="false"
"no-frame-pointer-elim-non-leaf"="false"
"no-infs-fp-math"="false"
"no-nans-fp-math"="false"
"unsafe-fp-math"="false"
"use-soft-float"="false" }
My gut says f2 should be our canonicalization target because it doesn't
have a variable width shift while f1 and f3 both do while having the same
number immediates as f3.
Thoughts? Is it not worth looking into?
Thanks
--
David Majnemer
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20130608/b252c0fa/attachment.html>