[all-commits] [llvm/llvm-project] 8a0b2c: [InstCombine] Transform bitwise (A >> C - 1, zext(...

XChy via All-commits all-commits at lists.llvm.org
Mon Jul 24 04:07:56 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8a0b2ca8217f3c4380c43ffd8d6b679db3805822
      https://github.com/llvm/llvm-project/commit/8a0b2ca8217f3c4380c43ffd8d6b679db3805822
  Author: XChy <xxs_chy at outlook.com>
  Date:   2023-07-24 (Mon, 24 Jul 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    M llvm/test/Transforms/InstCombine/and-or-icmps.ll

  Log Message:
  -----------
  [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp))

This extends foldCastedBitwiseLogic to handle the similar cases.
I have recently submitted a patch to implement a single fold like:

(A > 0) | (A < 0) -> zext (A != 0)

But it is not general enough, and some problems like
a < b & a >= b - 1 happen again.

So I generalize this fold by matching the pattern
bitwise(A >> C - 1, zext(icmp)), and replace A >> C - 1 with
zext(A < 0) here. (C is the scalar size bits of the type of A.)

Then we get bitwise(zext(A < 0), zext(icmp)), this will be folded
by original code in foldCastedBitwiseLogic, into
zext(bitwise(A < 0, icmp)). And finally, any related icmp fold will
be automatically implemented because bitwise(icmp,icmp) had been
implemented.

The proof of the correctness is obvious, because the folds below
were previously proved and implemented.
  A >> C - 1 -> zext(A < 0)
  bitwise(zext(A), zext(B)) -> zext(bitwise(A, B))
And the fold of this patch is the combination of folds above.

Fixes https://github.com/llvm/llvm-project/issues/63751.

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




More information about the All-commits mailing list