[all-commits] [llvm/llvm-project] 4fd340: [KnownBits] Improve implementation of `KnownBits::...

goldsteinn via All-commits all-commits at lists.llvm.org
Tue May 23 11:57:08 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4fd3401e76b6a153c617a13aa399bf5095f206f9
      https://github.com/llvm/llvm-project/commit/4fd3401e76b6a153c617a13aa399bf5095f206f9
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M llvm/lib/Support/KnownBits.cpp
    M llvm/test/Analysis/ValueTracking/knownbits-abs.ll
    M llvm/unittests/Support/KnownBitsTest.cpp

  Log Message:
  -----------
  [KnownBits] Improve implementation of `KnownBits::abs`

`abs` preserves the lowest set bit, so if we know the lowest set bit,
set it in the output.

As well, implement the case where the operand is known negative.

Reviewed By: foad, RKSimon

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


  Commit: 1e963b40813e18e3b285cab35a05b5e0fe166eec
      https://github.com/llvm/llvm-project/commit/1e963b40813e18e3b285cab35a05b5e0fe166eec
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    A llvm/test/Analysis/ValueTracking/knownbits-sat-addsub.ll

  Log Message:
  -----------
  [ValueTracking] Add tests for knownbits of saturating add/sub functions; NFC

Reviewed By: RKSimon

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


  Commit: 5f50b180c50e5108b8b18d167147bef8c00fe532
      https://github.com/llvm/llvm-project/commit/5f50b180c50e5108b8b18d167147bef8c00fe532
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M llvm/include/llvm/Support/KnownBits.h
    M llvm/lib/Support/KnownBits.cpp
    M llvm/unittests/Support/KnownBitsTest.cpp

  Log Message:
  -----------
  [KnownBits] Add implementations for saturating add/sub functions

These where previously missing. Even in the case where overflow is
indeterminate we can still deduce some of the low/high bits.

Reviewed By: RKSimon

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


  Commit: 8a60814ed56c45bdc469fc215bca0aacb0e5b457
      https://github.com/llvm/llvm-project/commit/8a60814ed56c45bdc469fc215bca0aacb0e5b457
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M llvm/lib/Analysis/ValueTracking.cpp
    M llvm/test/Analysis/ValueTracking/knownbits-sat-addsub.ll

  Log Message:
  -----------
  [ValueTracking] Use `KnownBits` functions for `computeKnownBits` of saturating add/sub functions

The knownbits implementation covers all the cases previously handled
by `uadd.sat`/`usub.sat` as well some additional ones. We previously
were not handling the `ssub.sat`/`sadd.sat` cases at all.

Reviewed By: RKSimon

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


  Commit: 530bbc8f6919bc5bd61111cb02fe801e5825f5b7
      https://github.com/llvm/llvm-project/commit/530bbc8f6919bc5bd61111cb02fe801e5825f5b7
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    A llvm/test/Analysis/ValueTracking/select-known-non-zero-const.ll
    A llvm/test/Analysis/ValueTracking/select-known-non-zero.ll

  Log Message:
  -----------
  [ValueTracking] Add tests for using condition in select for non-zero analysis; NFC

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


  Commit: 2622b2f409f7a7a51f11d5eab3976785b47c1a7b
      https://github.com/llvm/llvm-project/commit/2622b2f409f7a7a51f11d5eab3976785b47c1a7b
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M llvm/lib/Analysis/ValueTracking.cpp
    M llvm/test/Analysis/ValueTracking/select-known-non-zero-const.ll
    M llvm/test/Analysis/ValueTracking/select-known-non-zero.ll
    M llvm/test/Transforms/InstSimplify/compare.ll

  Log Message:
  -----------
  [ValueTracking] Use `select` condition to help determine if `select` is non-zero

In `select c, x, y` the condition `c` dominates the resulting `x` or
`y` chosen by the `select`. This adds logic to `isKnownNonZero` to try
and use the `icmp` for the `c` condition to see if it implies the
select `x` or `y` are known non-zero.

For example in:
    ```
    %c = icmp ugt i8 %x, %C
    %r = select i1 %c, i8 %x, i8 %y
    ```
    The true arm of select `%x` is non-zero (when "returned" by the
    `select`) because `%c` being true implies `%x` is non-zero.

Alive2 Links (with `x {pred} C`):
    - EQ  iff `C != 0`:
        - https://alive2.llvm.org/ce/z/umLabn
    - NE  iff `C == 0`:
        - https://alive2.llvm.org/ce/z/DQvy8Y
    - UGT [always]:
        - https://alive2.llvm.org/ce/z/HBkjgQ
    - UGE iff `C != 0`:
        - https://alive2.llvm.org/ce/z/LDNifB
    - SGT iff `C s>= 0`:
        - https://alive2.llvm.org/ce/z/QzWDj3
    - SGE iff `C s> 0`:
        - https://alive2.llvm.org/ce/z/rR4g3D
    - SLT iff `C s<= 0`:
        - https://alive2.llvm.org/ce/z/uysayx
    - SLE iff `C s< 0`:
        - https://alive2.llvm.org/ce/z/2jYc7e

Reviewed By: nikic

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


Compare: https://github.com/llvm/llvm-project/compare/806b0cd5ab56...2622b2f409f7


More information about the All-commits mailing list