[PATCH] D153540: [LoopUnroll] Fold add chains during unrolling

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 05:52:01 PDT 2023


nikic created this revision.
nikic added reviewers: fhahn, reames.
Herald added subscribers: luke, StephenFan, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, nemanjai.
Herald added a project: All.
nikic requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, MaskRay.
Herald added a project: LLVM.

Loop unrolling tends to produce chains of `%x1 = add %x0, 1; `%x2 = add %x1, 1; ...` with one add per unrolled iteration. This patch proposed to simplify these adds to `%xN = add %x0, N` directly during unrolling, rather than waiting for InstCombine to do so.

The motivation for this is that having a single add (rather than an add chain) on the induction variable makes it a simple recurrence, which we specially recognize in a number of places. This allows InstCombine to directly perform folds with that knowledge, instead of first folding the add chains, and then doing other folds in another InstCombine iteration.

Due to the reduced number of InstCombine iterations, this also results in a small compile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=4c748821cd18a13898db87cbe4925e5f26af1fab&to=e21a18f8e74a7bdb1bf98fbe1ce6accce3a10a0a&stat=instructions:u


https://reviews.llvm.org/D153540

Files:
  llvm/lib/Transforms/Utils/LoopUnroll.cpp
  llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll
  llvm/test/DebugInfo/unrolled-loop-remainder.ll
  llvm/test/Transforms/LoopUnroll/2011-08-08-PhiUpdate.ll
  llvm/test/Transforms/LoopUnroll/AArch64/partial.ll
  llvm/test/Transforms/LoopUnroll/ARM/instr-size-costs.ll
  llvm/test/Transforms/LoopUnroll/ARM/loop-unrolling.ll
  llvm/test/Transforms/LoopUnroll/ARM/multi-blocks.ll
  llvm/test/Transforms/LoopUnroll/PowerPC/p7-unrolling.ll
  llvm/test/Transforms/LoopUnroll/PowerPC/p8-unrolling-legalize-vectors-inseltpoison.ll
  llvm/test/Transforms/LoopUnroll/PowerPC/p8-unrolling-legalize-vectors.ll
  llvm/test/Transforms/LoopUnroll/RISCV/unroll.ll
  llvm/test/Transforms/LoopUnroll/X86/mmx.ll
  llvm/test/Transforms/LoopUnroll/full-unroll-keep-first-exit.ll
  llvm/test/Transforms/LoopUnroll/nonlatchcondbr.ll
  llvm/test/Transforms/LoopUnroll/partial-unroll-non-latch-exit.ll
  llvm/test/Transforms/LoopUnroll/partially-unroll-unconditional-latch.ll
  llvm/test/Transforms/LoopUnroll/runtime-exit-phi-scev-invalidation.ll
  llvm/test/Transforms/LoopUnroll/runtime-loop-at-most-two-exits.ll
  llvm/test/Transforms/LoopUnroll/runtime-loop-multiexit-dom-verify.ll
  llvm/test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll
  llvm/test/Transforms/LoopUnroll/runtime-loop5.ll
  llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll
  llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll
  llvm/test/Transforms/LoopUnroll/runtime-unroll-assume-no-remainder.ll
  llvm/test/Transforms/LoopUnroll/scev-invalidation-lcssa.ll
  llvm/test/Transforms/LoopUnroll/shifted-tripcount.ll
  llvm/test/Transforms/LoopUnroll/tripcount-overflow.ll
  llvm/test/Transforms/LoopUnroll/unroll-header-exiting-with-phis.ll
  llvm/test/Transforms/LoopUnroll/unroll-opt-attribute.ll
  llvm/test/Transforms/LoopUnrollAndJam/dependencies_visit_order.ll
  llvm/test/Transforms/LoopUnrollAndJam/unroll-and-jam.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153540.533574.patch
Type: text/x-patch
Size: 287809 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230622/63e4af95/attachment-0001.bin>


More information about the llvm-commits mailing list