[PATCH] D147532: [MachineLateInstrsCleanup] Improve compile time for huge functions.

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 06:56:05 PDT 2023


jonpa created this revision.
jonpa added reviewers: vpykhtin, uabelho, foad, craig.topper, arsenm.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
jonpa requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

It was discovered that this pass can be slow on huge functions, meaning 20% compile time instead of the usual ~0.5% (with a test case spending ~19 mins on SystemZ just in the backend with llc).

The problem relates to the necessary clearing of the kill flags when a redundant instruction is removed. This was made by scanning backwards over the instructions until a use(/def) was found (I tried simply clearing all kill flags on the involved registers, but that did change a few cases of later optimizations, so it seems that this should not be simplified like that).

This patch replaces the scanning of instructions with a map from register to the last seen use (kill).

Compile time on the huge file has been remedied fully (-> 0.4%), but I see on SystemZ/SPEC a slight average compile time increase (0.46% -> 0.52%). This is small enough that it seems wise to go ahead and use the map to help the huge functions (or..?).

Some alternate experiments with this has already been made at https://reviews.llvm.org/D146810, but this turned out to be the simpler version with the same performance.

Fixes: https://github.com/llvm/llvm-project/issues/61397


https://reviews.llvm.org/D147532

Files:
  llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147532.510790.patch
Type: text/x-patch
Size: 6722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230404/37416524/attachment.bin>


More information about the llvm-commits mailing list