summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/RegisterCoalescer.cpp
AgeCommit message (Collapse)Author
2025-05-22[LLVM][CodeGen] Add convenience accessors for MachineFunctionProperties ↵users/pcc/spr/main.elf-add-branch-to-branch-optimizationRahul Joshi
(#140002) Add per-property has<Prop>/set<Prop>/reset<Prop> functions to MachineFunctionProperties.
2025-04-13[CodeGen] Use llvm::append_range (NFC) (#135567)Kazu Hirata
2025-03-14[CodeGen] Remove parameter from LiveRangeEdit::canRematerializeAt [NFC]Philip Reames
Only one caller cares about the true case of this parameter, so move the check to that single caller. Note that RegisterCoalescer seems like it should care, but it already duplicates the check several lines above.
2025-03-03RegisterCoalescer: Avoid repeated getRegClass on all paths (#129490)Matt Arsenault
2025-03-02[CodeGen] Use Register::id() to avoid implicit cast. NFCCraig Topper
2025-02-03[CodeGen][NewPM] Port RegisterCoalescer to NPM (#124698)Akshat Oke
2025-01-31[CodeGen]RegisterCoalescer: Remove the print() method (#125042)Akshat Oke
I saw that there used to be an overload `operator<<(OS, const Pass &P)`. Now that it's gone, I still don't find anyone using the print method except the internal debug printing hidden under `LLVM_DEBUG` in this function.
2025-01-29[CodeGen] RegisterCoalescer: Remove unused AliasAnalysis dependency (#124773)Akshat Oke
2025-01-28[CodeGen][NFC] Format RegisterCoalescer sources (#124697)Akshat Oke
2025-01-22Revert "Reland "RegisterCoalescer: Add implicit-def of super register when ↵Sander de Smalen
coalescing SUBREG_TO_REG" (#123632)" There's a regression with one of the bootstrap builds for x86. I'll revert this while I investigate. This reverts commit 4df6d3df24ae9cff07c70c96a1663cbba6e1dca5.
2025-01-22Reland "RegisterCoalescer: Add implicit-def of super register when ↵Sander de Smalen
coalescing SUBREG_TO_REG" (#123632) This PR aims to reland work done by @arsenm which was previously reverted due to some tangentially related scheduler issues as discussed on #76416. This PR cherry-picks the original commit (0e46b49de433), and adds another patch on top with the following changes: * The code in `updateRegDefsUses` now updates subranges when subreg-liveness-tracking is enabled. * When adding an implicit-def operand for the super-register, the code in `reMaterializeTrivialDef` which tries to remove undefined subranges should now take into account that the lanes from the super-reg are no longer undefined. Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2025-01-08[LLVM] Fix various cl::desc typos and whitespace issues (NFC) (#121955)Ryan Mansfield
2025-01-07[Coalescer] Consider NewMI's subreg index when updating lanemask. (#121780)Sander de Smalen
The code added in #116191 that updated the lanemasks for rematerialized values checked if `DefMI`'s destination register had a subreg index. This seems to have missed the following case: ``` %0:gpr32 = MOVi32imm 1 %1:gpr64 = SUBREG_TO_REG 0, %0:gpr32, %subreg.sub_32 ``` which during rematerialization would have the following variables set: ``` DefMI = %0:gpr32 = MOVi32imm 1 NewMI = %3.sub_32:gpr64 = MOVi32imm 1 (rematerialized value) ``` When checking whether the lanemasks need to be generated, considering whether DefMI's destination has a subreg index is insufficient, we should look at DefMI's subreg index instead. The added tests are a bit more involved, because I was not able to reconstruct the issue without having some control flow in the test. These tests come from actual reproducers.
2025-01-07[Coalescer] Move code added in #116191 (#121779)Sander de Smalen
By moving the code a bit later, we can factor out some of the conditions as those are now already tested. This will also be useful when adding another fix on top that uses `NewMI`'s subreg index (to follow as a separate PR). The change is intended to be NFC.
2025-01-07RegisterCoalescer: Fix assert on remat to copy-to-physreg with subregs (#121734)Matt Arsenault
Do not try to rematerialize a super-register def used by a subregister extract copy into a copy to a physical register if the other pieces of the full physreg are live at the rematerialization point. It would insert the super-register def at the rematerialization point, and assert since the other half of the register was already live. This is analagous to the undef subregister def handling above, which handled the virtual register case. Fixes #120970
2024-12-02RegisterCoalescer: Set undef on full register uses when coalescing ↵Matt Arsenault
implicit_def (#118321) Previously this would delete the IMPLICIT_DEF and not introduce the undef flag on the use operand. Fixes sub-issue found while reducing #109294
2024-11-28RegisterCoalescer: Fix creating full / empty subrange on undef subreg use ↵Matt Arsenault
(#117936)
2024-11-28Reland "[RegisterCoalescer] Fix up subreg lanemasks after rematerializing. ↵Sander de Smalen
(#116191)" This patch can now reland after 318c69de52b6 relanded #114827. This reverts commit 14a58a1390a72ba6c66606e58e86425dcb902763.
2024-11-22Revert "[RegisterCoalescer] Fix up subreg lanemasks after rematerializing. ↵Vitaly Buka
(#116191)" (#117367) To pass tests with #117307 revert. This reverts commit 3093b29b597b9a936a3e4d1c8bc4a7ccba8fc848.
2024-11-19[RegisterCoalescer] Fix up subreg lanemasks after rematerializing. (#116191)Sander de Smalen
In a situation like the following: ``` undef %2.subreg = INST %1 ; DefMI (rematerializable), ; DefSubIdx = subreg %3 = COPY %2 ; SrcIdx = DstIdx = 0 .... = SOMEINSTR %3, %2 ``` there are no subranges for `%3` because the entire register is copied, but after rematerialization the subrange of the rematerialized value must be fixed up with the appropriate subranges for `.subreg`. (To me this issue seemed a bit similar to the issue fixed by #96839, but then related to rematerialization)
2024-09-24llvm-reduce: Don't print verifier failed machine functions (#109673)Matt Arsenault
This produces far too much terminal output, particularly for the instruction reduction. Since it doesn't consider the liveness of of the instructions it's deleting, it produces quite a lot of verifier errors.
2024-09-24LiveInterval: Make verify functions return bool (#109672)Matt Arsenault
This will allow the MachineVerifier to check these properties instead of just asserting
2024-08-26[CodeGen] Use MachineInstr::all_defs (NFC) (#106017)Kazu Hirata
2024-07-26[CodeGen] Remove AA parameter of isSafeToMove (#100691)Pengcheng Wang
This `AA` parameter is not used and for most uses they just pass a nullptr. The use of `AA` was removed since 8d0383e.
2024-07-23[RegisterCoalescer] Fix SUBREG_TO_REG handling in the RegisterCoalescer. ↵Stefan Pintilie
(#96839) The issue with the handling of the SUBREG_TO_REG is that we don't join the subranges correctly when we join live ranges across the SUBREG_TO_REG. For example when joining across this: ``` 32B %2:gr64_nosp = SUBREG_TO_REG 0, %0:gr32, %subreg.sub_32bit ``` we want to join these live ranges: ``` %0 [16r,32r:0) 0@16r weight:0.000000e+00 %2 [32r,112r:0) 0@32r weight:0.000000e+00 ``` Before the fix the range for the resulting merged `%2` is: ``` %2 [16r,112r:0) 0@16r weight:0.000000e+00 ``` After the fix it is now this: ``` %2 [16r,112r:0) 0@16r L000000000000000F [16r,112r:0) 0@16r weight:0.000000e+00 ``` Two tests are added to this fix. The X86 test fails without the patch. The PowerPC test passes with and without the patch but is added as a way track future possible failures when register classes are changed in a future patch.
2024-07-10[CodeGen][NewPM] Port `LiveIntervals` to new pass manager (#98118)paperchalice
- Add `LiveIntervalsAnalysis`. - Add `LiveIntervalsPrinterPass`. - Use `LiveIntervalsWrapperPass` in legacy pass manager. - Use `std::unique_ptr` instead of raw pointer for `LICalc`, so destructor and default move constructor can handle it correctly. This would be the last analysis required by `PHIElimination`.
2024-07-09[CodeGen][NewPM] Port `SlotIndexes` to new pass manager (#97941)paperchalice
- Add `SlotIndexesAnalysis`. - Add `SlotIndexesPrinterPass`. - Use `SlotIndexesWrapperPass` in legacy pass.
2024-07-09[CodeGen][NewPM] Port `machine-loops` to new pass manager (#97793)paperchalice
- Add `MachineLoopAnalysis`. - Add `MachineLoopPrinterPass`. - Convert to `MachineLoopInfoWrapperPass` in legacy pass manager.
2024-06-26[CodeGen] Use range-based for loops (NFC) (#96777)Kazu Hirata
2024-06-14[llvm] Use llvm::unique (NFC) (#95628)Kazu Hirata
2024-06-06RegisterCoalescer: Remove unnecessary maybe_unusedMatt Arsenault
2214026e957397cc6385f778b28d570485a31856 didn't fix an unused variable warning correctly.
2024-04-24[CodeGen] Make the parameter TRI required in some functions. (#85968)Xu Zhang
Fixes #82659 There are some functions, such as `findRegisterDefOperandIdx` and `findRegisterDefOperand`, that have too many default parameters. As a result, we have encountered some issues due to the lack of TRI parameters, as shown in issue #82411. Following @RKSimon 's suggestion, this patch refactors 9 functions, including `{reads, kills, defines, modifies}Register`, `registerDefIsDead`, and `findRegister{UseOperandIdx, UseOperand, DefOperandIdx, DefOperand}`, adjusting the order of the TRI parameter and making it required. In addition, all the places that call these functions have also been updated correctly to ensure no additional impact. After this, the caller of these functions should explicitly know whether to pass the `TargetRegisterInfo` or just a `nullptr`.
2024-02-09Reapply "[RegisterCoalescer] Clear instructions not recorded in ↵DianQK
`ErasedInstrs` but erased (#79820)" This reverts commit 8316bf34ac21117f35bc8e6fafa2b3e7da75e1d5.
2024-02-09Revert "[RegisterCoalescer] Clear instructions not recorded in ↵DianQK
`ErasedInstrs` but erased (#79820)" This reverts commit 95b14da678f4670283240ef4cf60f3a39bed97b4.
2024-02-09[RegisterCoalescer] Clear instructions not recorded in `ErasedInstrs` but ↵Quentin Dian
erased (#79820) Fixes #79718. Fixes #71178. The same instructions may exist in an iteration. We cannot immediately delete instructions in `ErasedInstrs`.
2024-01-03Revert "Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Arthur Eubanks
coalescing SUBREG_TO_REG"" This reverts commit 0e46b49de43349f8cbb2a7d4c6badef6d16e31ae. Causes crashes, see repro on https://github.com/llvm/llvm-project/commit/0e46b49de43349f8cbb2a7d4c6badef6d16e31ae.
2023-12-24[CodeGen] Use range-based for loops (NFC)Kazu Hirata
2023-12-22Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Matt Arsenault
coalescing SUBREG_TO_REG" This reverts commit c398fa009a47eb24f88383d5e911e59e70f8db86. PPC backend was fixed in 2f82662ce901c6666fceb9c6c5e0de216a1c9667
2023-12-16Revert "Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Stefan Pintilie
coalescing SUBREG_TO_REG"" This reverts commit f4b5be1ecdc85ca4257b739afb8d57e23c7a8030. The above change was breaking the clang-ppc64le-linux-test-suite bot.
2023-12-15Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Matt Arsenault
coalescing SUBREG_TO_REG" This reverts commit 69c4930aad9659ec6ab846c8e7124d6afe044b1e. See if this sticks after a few more coalescer assertions are fixed.
2023-12-13RegisterCoalescer: Fix implicit operand handling during rematerialize (#75271)Matt Arsenault
If the rematerialize was placing a subregister into a super register, and implicit operands referenced the original register, we need to add undef flags to the now-subregister indexed implicit operands. Depends #75152
2023-12-13RegisterCoalescer: Add undef flags in removePartialRedundancy (#75152)Matt Arsenault
If the copy being hoisted was undef, we have the same problems that eliminateUndefCopy needs to solve. We would effectively be introducing a new live out implicit_def. We need to add an undef flag to avoid artificially introducing a live through undef value. Previously, the verifier would fail due to the dead def inside the loop providing the live in value for the %1 use.
2023-12-06Revert "Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Thurston Dang
coalescing SUBREG_TO_REG"" This reverts commit 1f283a60a4bb896fa2d37ce00a3018924be82b9f. Reason: breaks MSan buildbot (https://lab.llvm.org/buildbot/#/builders/74/builds/24077)
2023-12-06Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Matt Arsenault
coalescing SUBREG_TO_REG" This reverts commit 9e50c6e6b5741895f58f3e530004052844b6af9f. A few assertion and verifier errors have been fixed in the coalescer and allocator, so hopefully this sticks this time.
2023-12-04RegisterCoalescer: Fix producing malformed IMPLICIT_DEFs (#73784)Matt Arsenault
If this was coalescing a SUBREG_TO_REG as a copy, the resulting instruction would be an IMPLICIT_DEF with an unexpected 2 immediate operands, which need to be dropped. Until recently the verifier did not catch this error, and an assert would fire if later the broken IMPLICIT_DEF was rematerialized P #73758 is related, it changes the failure mode to a verifier error.
2023-11-07Revert "Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Mitch Phillips
coalescing SUBREG_TO_REG"" This reverts commit ba385ae210b3659bc9dfb78ef1d280d03c2c3b5a. Reason: Broke the MSan buildbot. See comments on https://github.com/llvm/llvm-project/commit/ba385ae210b3659bc9dfb78ef1d280d03c2c3b5a for more information.
2023-11-07RegisterCoalescer: Clear isSSA propertyMatt Arsenault
Fix some expensive checks verifier errors on MIR tests.
2023-11-07Reapply "RegisterCoalescer: Add implicit-def of super register when ↵Matt Arsenault
coalescing SUBREG_TO_REG" This reverts commit e0f86ca2004b2d87ffe3c1e8242650a29fa98a82. This was hitting some assertions which have since been relaxed.
2023-10-31RegisterCoalescer: Relax assert for super register def rematerialization ↵Matt Arsenault
(#69088)
2023-10-05MachineFunctionPass: Clear properties before running function (#67962)Matt Arsenault
This ensures !isSSA checks in the function work if the input MIR happened to appear as SSA.