[PATCH] D149136: [LICM] Don't duplicate instructions just because they're free

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 02:06:07 PDT 2023


nikic created this revision.
nikic added reviewers: fhahn, asbirlea, mkazantsev, efriedma.
Herald added subscribers: StephenFan, hiraditya, nemanjai.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

D37076 <https://reviews.llvm.org/D37076> makes LICM duplicate instructions into exit blocks if the instruction is free. For GEPs, the motivation appears to be that this allows the GEP to be folded into addressing modes, while non-foldable users outside the loop might prevent this. TBH I don't think LICM is the place to do this (why doesn't CGP apply this heuristic itself?) but at least I understand the motivation.

However, the transform is also applied to all other "free" instructions, which are just that (removed during lowering and not "folded" in some way). For such instruction, this transform seems somewhere between useless, counter-productive (undoing CSE/GVN) and actively incorrect. For example, this transform can duplicate `freeze` instructions, which is illegal.

This patch limits the transform to just foldable GEPs, though we might want to drop it from LICM entirely as a followup.

This is a small compile-time improvement, because querying TTI cost model for every single instruction is expensive: http://llvm-compile-time-tracker.com/compare.php?from=057b5f1f3573ddceb04d9eb6fb9973358d53fece&to=1211bdf470f784888b8bef867e1e613539998e9b&stat=instructions:u


https://reviews.llvm.org/D149136

Files:
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/test/CodeGen/PowerPC/atomicrmw-uinc-udec-wrap.ll
  llvm/test/Transforms/LICM/pr23608.ll
  llvm/test/Transforms/LICM/sink-foldable.ll
  llvm/test/Transforms/LICM/sinking.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149136.516710.patch
Type: text/x-patch
Size: 8362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230425/88bac236/attachment.bin>


More information about the llvm-commits mailing list