diff options
author | Shoreshen <372660931@qq.com> | 2025-08-13 10:41:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-13 10:41:44 +0800 |
commit | db96363c0ace379147f333bf917e9050608c5083 (patch) | |
tree | 5e7a60697a181873baa2d0460283b5de900292d7 /llvm/lib/CodeGen/MachineInstrBundle.cpp | |
parent | d40d04f9d6b3a3a4f0336689f038936f5a58036d (diff) | |
download | llvm-db96363c0ace379147f333bf917e9050608c5083.zip llvm-db96363c0ace379147f333bf917e9050608c5083.tar.gz llvm-db96363c0ace379147f333bf917e9050608c5083.tar.bz2 |
[AMDGPU] Avoid put implicit_def into bundle that break reg's liveness (#142563)
Cause:
1. `implicit_def` inside bundle does not count for define of reg in
machineinst verifier
2. Including `implicit_def` will cause relative reg not define, result
in `Bad machine code: Using an undefined physical register` in the
machineinst verifier
Fixes https://github.com/llvm/llvm-project/issues/139102
---------
Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstrBundle.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstrBundle.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp index 4da0184..d9e8484 100644 --- a/llvm/lib/CodeGen/MachineInstrBundle.cpp +++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp @@ -94,6 +94,22 @@ static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, return DebugLoc(); } +/// Check if target reg is contained in given lists, which are: +/// LocalDefsV as given list for virtual regs +/// LocalDefsP as given list for physical regs, in BitVector[RegUnit] form +static bool containsReg(SmallSetVector<Register, 32> LocalDefsV, + const BitVector &LocalDefsP, Register Reg, + const TargetRegisterInfo *TRI) { + if (Reg.isPhysical()) { + for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg())) + if (!LocalDefsP[Unit]) + return false; + + return true; + } + return LocalDefsV.contains(Reg); +} + /// finalizeBundle - Finalize a machine instruction bundle which includes /// a sequence of instructions starting from FirstMI to LastMI (exclusive). /// This routine adds a BUNDLE instruction to represent the bundle, it adds @@ -115,6 +131,7 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, Bundle.prepend(MIB); SmallSetVector<Register, 32> LocalDefs; + BitVector LocalDefsP(TRI->getNumRegUnits()); SmallSet<Register, 8> DeadDefSet; SmallSet<Register, 16> KilledDefSet; SmallSetVector<Register, 8> ExternUses; @@ -130,7 +147,7 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, if (!Reg) continue; - if (LocalDefs.contains(Reg)) { + if (containsReg(LocalDefs, LocalDefsP, Reg, TRI)) { MO.setIsInternalRead(); if (MO.isKill()) { // Internal def is now killed. @@ -165,8 +182,10 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, } } - if (!MO.isDead() && Reg.isPhysical()) - LocalDefs.insert_range(TRI->subregs(Reg)); + if (!MO.isDead() && Reg.isPhysical()) { + for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg())) + LocalDefsP.set(Unit); + } } // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions |