[all-commits] [llvm/llvm-project] 1436a9: [LVI] Look through negations when evaluating condi...

Keno Fischer via All-commits all-commits at lists.llvm.org
Thu Jan 5 15:05:07 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1436a9232b10487a097f62bf85025fc6b6b66fde
      https://github.com/llvm/llvm-project/commit/1436a9232b10487a097f62bf85025fc6b6b66fde
  Author: Keno Fischer <keno at juliacomputing.com>
  Date:   2023-01-05 (Thu, 05 Jan 2023)

  Changed paths:
    M llvm/lib/Analysis/LazyValueInfo.cpp
    M llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

  Log Message:
  -----------
  [LVI] Look through negations when evaluating conditions

This teaches LVI (and thus CVP) to extract range information
from branches whose condition is negated using (`xor %c, true`).
On the implementation side, we switch the cache to additionally
track whether we're looking for the inverted value or not and
otherwise using the existing support for computing inverted
conditions.

I think the biggest question here is why this negation shows up
here at all. After all, it should always be possible for some
other pass to fold such a negation into a branch, comparison or
some other logical operation. Indeed, instcombine does just that.
However, these negations can be otherwise fairly persistent, e.g.
instsimplify is not able to exchange branch conditions from
negations. In addition, jumpthreading, which sits at the same
point in default pass pipeline also handles this pattern, which
adds further evidence that we might expect these negations to
not have been canonicalized away yet at this point in the pass
pipeline.

In the particular case I was looking at there was a bit of a
circular dependency where flags computed by cvp were needed
by instcombine, and incstombine's folding of the negation was
needed for cvp. Adding a second instombine pass would have
worked of course, but instcombine can be somewhat expensive,
so it appeared desirable to not require it to have run
before cvp (as is the case in the default pass pipeline).

Reviewed By: nikic

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




More information about the All-commits mailing list