[all-commits] [llvm/llvm-project] 065900: [LICM] Don't duplicate instructions just because t...

Nikita Popov via All-commits all-commits at lists.llvm.org
Fri Apr 28 05:31:39 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0659000ff79decc1173aac140d4b0325fe696c57
      https://github.com/llvm/llvm-project/commit/0659000ff79decc1173aac140d4b0325fe696c57
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2023-04-28 (Fri, 28 Apr 2023)

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

  Log Message:
  -----------
  [LICM] Don't duplicate instructions just because they're free

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 instructions, 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.

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




More information about the All-commits mailing list