Skip to content
  • Chandler Carruth's avatar
    Switch the lowering of CTLZ_ZERO_UNDEF from a .td pattern back to the · 7e9453e9
    Chandler Carruth authored
    X86ISelLowering C++ code. Because this is lowered via an xor wrapped
    around a bsr, we want the dagcombine which runs after isel lowering to
    have a chance to clean things up. In particular, it is very common to
    see code which looks like:
    
      (sizeof(x)*8 - 1) ^ __builtin_clz(x)
    
    Which is trying to compute the most significant bit of 'x'. That's
    actually the value computed directly by the 'bsr' instruction, but if we
    match it too late, we'll get completely redundant xor instructions.
    
    The more naive code for the above (subtracting rather than using an xor)
    still isn't handled correctly due to the dagcombine getting confused.
    
    Also, while here fix an issue spotted by inspection: we should have been
    expanding the zero-undef variants to the normal variants when there is
    an 'lzcnt' instruction. Do so, and test for this. We don't want to
    generate unnecessary 'bsr' instructions.
    
    These two changes fix some regressions in encoding and decoding
    benchmarks. However, there is still a *lot* to be improve on in this
    type of code.
    
    llvm-svn: 147244
    7e9453e9
Loading