[all-commits] [llvm/llvm-project] 8e8467: [InstCombine] canonicalize "extract lowest set bit...

Sanjay Patel via All-commits all-commits at lists.llvm.org
Sun Feb 19 15:11:18 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8e8467d9d8033e22a98aec3bc20969bd3a59ab28
      https://github.com/llvm/llvm-project/commit/8e8467d9d8033e22a98aec3bc20969bd3a59ab28
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2023-02-19 (Sun, 19 Feb 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
    M llvm/test/Transforms/InstCombine/shift.ll

  Log Message:
  -----------
  [InstCombine] canonicalize "extract lowest set bit" away from cttz intrinsic

1 << (cttz X) --> -X & X
https://alive2.llvm.org/ce/z/qv3E9e

This creates an extra use of the input value, so that's generally
not preferred, but there are advantages to this direction:
1. 'negate' and 'and' allow for better analysis than 'cttz'.
2. This is more likely to induce follow-on transforms (in the
   example from issue #60801, we'll get the decrement pattern).
3. The more basic ALU ops are more likely to result in better
   codegen across a variety of targets.

This won't solve the motivating bugs (see issue #60799) because
we do not recognize the redundant icmp+sel, and the x86 backend
may not have the pattern-matching to produce the optimal BMI
instructions.

Differential Revision: https://reviews.llvm.org/D144329




More information about the All-commits mailing list