CodeGenPrepare: Replace constant PHI arguments with switch condition value
authorMatthias Braun <matze@braunis.de>
Wed, 27 Apr 2022 01:27:21 +0000 (18:27 -0700)
committerMatthias Braun <matze@braunis.de>
Tue, 10 May 2022 17:00:10 +0000 (10:00 -0700)
commitf0ea9c9cec7f7b632ef7894ff7b3859269de611b
tree069eafb5958cae882e6d32ac1c33e56cc005763c
parentcd19af74c031f0f538050d00b26bab3fbca07414
CodeGenPrepare: Replace constant PHI arguments with switch condition value

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, ...); }

Differential Revision: https://reviews.llvm.org/D124552
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/CodeGen/X86/ragreedy-hoist-spill.ll
llvm/test/CodeGen/X86/speculative-load-hardening-indirect.ll
llvm/test/CodeGen/X86/switch-phi-const.ll
llvm/test/Transforms/CodeGenPrepare/X86/switch-phi-const.ll [new file with mode: 0644]