aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2024-01-18 10:48:10 +0000
committerGitHub <noreply@github.com>2024-01-18 10:48:10 +0000
commit40d952b8748bf5c4a97fc82296e1fc050388472f (patch)
tree85d46eb9bf0a63425266aaed59c66a3ecac95570 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parentba52f06f9d92c7ca04b440f618f8d352ea121fcc (diff)
downloadllvm-40d952b8748bf5c4a97fc82296e1fc050388472f.zip
llvm-40d952b8748bf5c4a97fc82296e1fc050388472f.tar.gz
llvm-40d952b8748bf5c4a97fc82296e1fc050388472f.tar.bz2
[CGP] Avoid replacing a free ext with multiple other exts. (#77094)
Replacing a free extension with 2 or more extensions unnecessarily increases the number of IR instructions without providing any benefits. It also unnecessarily causes operations to be performed on wider types than necessary. In some cases, the extra extensions also pessimize codegen (see bfis-in-loop.ll). The changes in arm64-codegen-prepare-extload.ll also show that we avoid promotions that should only be performed in stress mode. PR: https://github.com/llvm/llvm-project/pull/77094
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index ff61f1a..8ee1f19 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -6013,7 +6013,9 @@ bool CodeGenPrepare::tryToPromoteExts(
// cut this search path, because it means we degrade the code quality.
// With exactly 2, the transformation is neutral, because we will merge
// one extension but leave one. However, we optimistically keep going,
- // because the new extension may be removed too.
+ // because the new extension may be removed too. Also avoid replacing a
+ // single free extension with multiple extensions, as this increases the
+ // number of IR instructions while not providing any savings.
long long TotalCreatedInstsCost = CreatedInstsCost + NewCreatedInstsCost;
// FIXME: It would be possible to propagate a negative value instead of
// conservatively ceiling it to 0.
@@ -6021,7 +6023,8 @@ bool CodeGenPrepare::tryToPromoteExts(
std::max((long long)0, (TotalCreatedInstsCost - ExtCost));
if (!StressExtLdPromotion &&
(TotalCreatedInstsCost > 1 ||
- !isPromotedInstructionLegal(*TLI, *DL, PromotedVal))) {
+ !isPromotedInstructionLegal(*TLI, *DL, PromotedVal) ||
+ (ExtCost == 0 && NewExts.size() > 1))) {
// This promotion is not profitable, rollback to the previous state, and
// save the current extension in ProfitablyMovedExts as the latest
// speculative promotion turned out to be unprofitable.