[all-commits] [llvm/llvm-project] 340ae4: [InstCombine] use isKnownNonNegative() for readabi...

Sanjay Patel via All-commits all-commits at lists.llvm.org
Sun Oct 16 08:14:09 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 340ae45be06ae663e73edbee3f942f5dcd13c58e
      https://github.com/llvm/llvm-project/commit/340ae45be06ae663e73edbee3f942f5dcd13c58e
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2022-10-16 (Sun, 16 Oct 2022)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

  Log Message:
  -----------
  [InstCombine] use isKnownNonNegative() for readability; NFCI

This should be functionally equivalent - both calls are thin
wrappers around computeKnownBits(). We'll probably want to use
known-bits directly in follow-up patches because that could
determine "exact" for example (see issue #58348).


  Commit: 78e3aeda3ce22d68362660b7712793d698800926
      https://github.com/llvm/llvm-project/commit/78e3aeda3ce22d68362660b7712793d698800926
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2022-10-16 (Sun, 16 Oct 2022)

  Changed paths:
    M llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
    M llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll

  Log Message:
  -----------
  [InstCombine] add tests for sdiv with (neg)pow2 divisor; NFC


  Commit: e5ee0b06d694fe7749b56706f1bf67e22eaef628
      https://github.com/llvm/llvm-project/commit/e5ee0b06d694fe7749b56706f1bf67e22eaef628
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2022-10-16 (Sun, 16 Oct 2022)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
    M llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll

  Log Message:
  -----------
  [InstCombine] try to determine "exact" for sdiv

If the divisor is a power-of-2 or negative-power-of-2 and the dividend
is known to have >= trailing zeros than the divisor, the division is exact:
https://alive2.llvm.org/ce/z/UGBksM (general proof)
https://alive2.llvm.org/ce/z/D4yPS- (examples based on regression tests)

This isn't the most direct optimization (we could create ashr in these
examples instead of relying on existing folds for exact divides), but
it's possible that there's a more general constraint than just a pow2
divisor, so this might be extended in the future.

This should solve issue #58348.

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


Compare: https://github.com/llvm/llvm-project/compare/067b744dbb02...e5ee0b06d694


More information about the All-commits mailing list