[PATCH] D141482: [LVI][CVP] Make use of condition known at use

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 04:59:32 PST 2023


nikic created this revision.
nikic added a reviewer: spatel.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When an instruction is only used in a select or phi operand, we might be able to make use of additional information from the select/branch condition. For example in

  %sub = call i16 @llvm.usub.sat.i16(i16 %x, i16 10)
  %cmp = icmp uge i16 %x, 10
  %sel = select i1 %cmp, i16 %sub, i16 42

the `usub.sat` is only used in a select where `%x uge 10` is known to hold, so we can fold it based on that knowledge.

This addresses the regression reported at https://reviews.llvm.org/D140798#4039748, but also provides a solution to a recurring problem we've had, where we fail to make use of range information after a branch+phi has been converted into a select. Our current solution to this is to hope that IPSCCP can perform the fold before that happens, but handling this in LVI is a somewhat more general solution.

Currently we only make use of this for the willNotOverflow() fold, but I plan to adjust other folds to use the new API as well.


https://reviews.llvm.org/D141482

Files:
  llvm/include/llvm/Analysis/LazyValueInfo.h
  llvm/lib/Analysis/LazyValueInfo.cpp
  llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
  llvm/test/Transforms/CorrelatedValuePropagation/cond-at-use.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141482.488161.patch
Type: text/x-patch
Size: 7526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230111/d27495c7/attachment.bin>


More information about the llvm-commits mailing list