For something like
authorEvan Cheng <evan.cheng@apple.com>
Mon, 16 Jul 2012 19:35:43 +0000 (19:35 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Mon, 16 Jul 2012 19:35:43 +0000 (19:35 +0000)
commit98819c9d1e3b929e9ebab0e8cd3edb31aad21bd8
tree382bd7339c243a3f753335d08a9d040a054aab37
parentc76fa8937d483ae83f94d0793254dbab78877687
For something like
uint32_t hi(uint64_t res)
{
        uint_32t hi = res >> 32;
        return !hi;
}

llvm IR looks like this:
define i32 @hi(i64 %res) nounwind uwtable ssp {
entry:
  %lnot = icmp ult i64 %res, 4294967296
  %lnot.ext = zext i1 %lnot to i32
  ret i32 %lnot.ext
}

The optimizer has optimize away the right shift and truncate but the resulting
constant is too large to fit in the 32-bit immediate field. The resulting x86
code is worse as a result:
        movabsq $4294967296, %rax       ## imm = 0x100000000
        cmpq    %rax, %rdi
        sbbl    %eax, %eax
        andl    $1, %eax

This patch teaches the x86 lowering code to handle ult against a large immediate
with trailing zeros. It will issue a right shift and a truncate followed by
a comparison against a shifted immediate.
        shrq    $32, %rdi
        testl   %edi, %edi
        sete    %al
        movzbl  %al, %eax

It also handles a ugt comparison against a large immediate with trailing bits
set. i.e. X >  0x0ffffffff -> (X >> 32) >= 1

rdar://11866926

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160312 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/2011-04-13-SchedCmpJmp.ll
test/CodeGen/X86/cmp.ll