[PATCH] D148001: [LICM] Reassociate & hoist add/sub expressions

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 02:28:12 PDT 2023


mkazantsev created this revision.
mkazantsev added reviewers: nikic, lebedev.ri, skatkov, fhahn, reames.
Herald added subscribers: StephenFan, asbirlea, javed.absar, hiraditya.
Herald added a project: All.
mkazantsev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LICM could reassociate mixed variant/invariant comparison/arithmetic operations
and hoist invariant parts out of loop if it can prove that they can be computed
without overflow. Motivating example here:

  INV1 - VAR1 < INV2

can be turned into

  VAR > INV1 - INV2

if we can prove no-signed-overflow here. Then `INV1 - INV2` can be computed
out of loop, so we save one arithmetic operation in-loop.

I tried to make it as general as possible in this patch. For some reason it only
works when no-overflow facts are known from non-contextual facts, but this
is maybe a limitation of SCEV. It can be a subject of further improvement in
SCEV.


https://reviews.llvm.org/D148001

Files:
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/test/Transforms/LICM/hoist-add-sub.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148001.512376.patch
Type: text/x-patch
Size: 12695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230411/1bae76d6/attachment.bin>


More information about the llvm-commits mailing list