[PATCH] D124552: CodeGenPrepare: Replace constant PHI arguments with switch condition value

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 27 13:29:59 PDT 2022


MatzeB created this revision.
MatzeB added reviewers: RKSimon, craig.topper, jnspaulsson, spatel, reames, nikic, wenlei.
Herald added subscribers: StephenFan, modimo, pengfei, hiraditya, mcrosier, qcolombet.
Herald added a project: All.
MatzeB requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We often see code like the following after running SCCP:

  switch (x) { case 42: phi(42, ...); }

This tends to produce bad code as we currently materialize the constant
phi-argument in the switch-block. This increases register pressure and if the
pattern repeats for `n` case statements, we end up generating `n` constant
values.

This changes CodeGenPrepare to catch this pattern and revert it back to:

  switch (x) { case 42: phi(x, ...); }

This fixes a part of https://github.com/llvm/llvm-project/issues/55153


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124552

Files:
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/test/CodeGen/X86/ragreedy-hoist-spill.ll
  llvm/test/CodeGen/X86/speculative-load-hardening-indirect.ll
  llvm/test/Transforms/CodeGenPrepare/X86/switch-phi-const.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124552.425597.patch
Type: text/x-patch
Size: 26037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220427/47a75e5e/attachment.bin>


More information about the llvm-commits mailing list