[all-commits] [llvm/llvm-project] 9020e2: [InstCombine] Convert xor (ashr X, BW-1), C -> sel...

David Green via All-commits all-commits at lists.llvm.org
Fri Oct 29 03:19:33 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9020e22a876e15afd7b5d13ac3abf180b5cf9343
      https://github.com/llvm/llvm-project/commit/9020e22a876e15afd7b5d13ac3abf180b5cf9343
  Author: David Green <david.green at arm.com>
  Date:   2021-10-29 (Fri, 29 Oct 2021)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    M llvm/test/Transforms/InstCombine/truncating-saturate.ll
    M llvm/test/Transforms/InstCombine/xor-ashr.ll

  Log Message:
  -----------
  [InstCombine] Convert xor (ashr X, BW-1), C -> select(X >=s 0, C, ~C)

The sequence of instructions `xor (ashr X, BW-1), C` (or with a truncation
`xor (trunc (ashr X, BW-1)), C)` takes a value, produces all zeros or all
ones and with it optionally inverts a constant depending on whether the
original input was positive or negative. This is the same as checking if
the value is positive, and selecting between the constant and ~constant.
https://alive2.llvm.org/ce/z/NJ85qY

This is a fairly general version of a fold that helps pull saturating
arithmetic into a canonical form.

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




More information about the All-commits mailing list