[all-commits] [llvm/llvm-project] d87bfa: [InstCombine] Combine instructions of type or/and ...

bipmis via All-commits all-commits at lists.llvm.org
Thu Jun 9 02:59:23 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d87bfa9ad0af6fa6e0e8a415acc5e8a621fab0d7
      https://github.com/llvm/llvm-project/commit/d87bfa9ad0af6fa6e0e8a415acc5e8a621fab0d7
  Author: Biplob Mishra <biplob.mishra at arm.com>
  Date:   2022-06-09 (Thu, 09 Jun 2022)

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

  Log Message:
  -----------
  [InstCombine] Combine instructions of type or/and where AND masks can be combined.

The patch simplifies some of the patterns as below

(A | (B & C0)) | (B & C1) -> A | (B & C0|C1)
((B & C0) | A) | (B & C1) -> (B & C0|C1) | A

In some scenarios like byte reverse on half word, we can see this pattern multiple times and this conversion can optimize these patterns.

Additionally this commit fixes the issue reported with the test case.
int f(int a, int b) {
  int c = ((unsigned char)(a >> 23) & 925);
  if (a)
    c = (a >> 23 & b) | ((unsigned char)(a >> 23) & 925) | (b >> 23 & 157);
  return c;
}

The previous revision/commit did not check one-use of an intermediate value that this transform re-uses.
When that value has another use, an existing transform will try to invert the transform here.
By adding one-use checks, we avoid the infinite loops seen with the earlier commit.

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




More information about the All-commits mailing list