Skip to content
  • Evan Cheng's avatar
    This is another case where instcombine demanded bits optimization created · f579beca
    Evan Cheng authored
    large immediates. Add dag combine logic to recover in case the large
    immediates doesn't fit in cmp immediate operand field.
    
    int foo(unsigned long l) {
      return (l>> 47) == 1;
    }
    
    we produce
    
      %shr.mask = and i64 %l, -140737488355328
      %cmp = icmp eq i64 %shr.mask, 140737488355328
      %conv = zext i1 %cmp to i32
      ret i32 %conv
    
    which codegens to
    
    movq    $0xffff800000000000,%rax
    andq    %rdi,%rax
    movq    $0x0000800000000000,%rcx
    cmpq    %rcx,%rax
    sete    %al
    movzbl    %al,%eax
    ret
    
    TargetLowering::SimplifySetCC would transform
    (X & -256) == 256 -> (X >> 8) == 1
    if the immediate fails the isLegalICmpImmediate() test. For x86,
    that's immediates which are not a signed 32-bit immediate.
    
    Based on a patch by Eli Friedman.
    
    PR10328
    rdar://9758774
    
    llvm-svn: 160346
    f579beca
Loading