[llvm] [CodeGen] Ensure clearRegisterKills clears inside bundles. (PR #149177)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 16 13:18:24 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Ricardo Jesus (rj-jesus)
<details>
<summary>Changes</summary>
When clearing register kills, ensure we do so inside a bundle too. This came up in AArch64LdStOpt where we attempt to clear kill flags that affect the first store's register. If the kill happens in a bundle, we were only clearing it in the bundle operands, but not in the constituent instructions. This was leading to a verification error, for example: https://godbolt.org/z/WjhEWGcPW.
Fixes #<!-- -->149092.
---
Full diff: https://github.com/llvm/llvm-project/pull/149177.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/MachineInstr.cpp (+4-4)
- (modified) llvm/test/CodeGen/AArch64/sve-vls-ldst-opt.mir (+20)
``````````diff
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index da3665b3b6a0b..a966add78a97e 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2177,12 +2177,12 @@ void MachineInstr::clearRegisterKills(Register Reg,
const TargetRegisterInfo *RegInfo) {
if (!Reg.isPhysical())
RegInfo = nullptr;
- for (MachineOperand &MO : operands()) {
- if (!MO.isReg() || !MO.isUse() || !MO.isKill())
+ for (MIBundleOperands O(*this); O.isValid(); ++O) {
+ if (!O->isReg() || !O->isUse() || !O->isKill())
continue;
- Register OpReg = MO.getReg();
+ Register OpReg = O->getReg();
if ((RegInfo && RegInfo->regsOverlap(Reg, OpReg)) || Reg == OpReg)
- MO.setIsKill(false);
+ O->setIsKill(false);
}
}
diff --git a/llvm/test/CodeGen/AArch64/sve-vls-ldst-opt.mir b/llvm/test/CodeGen/AArch64/sve-vls-ldst-opt.mir
index 49453bc178914..28c5220642ec5 100644
--- a/llvm/test/CodeGen/AArch64/sve-vls-ldst-opt.mir
+++ b/llvm/test/CodeGen/AArch64/sve-vls-ldst-opt.mir
@@ -72,3 +72,23 @@ body: |
# CHECK: STURQi killed renamable $q1, renamable $x1, 16 :: (store (s128))
# CHECK: STURQi killed renamable $q2, renamable $x1, 48 :: (store (s128))
# CHECK: STR_ZXI killed renamable $z3, renamable $x1, 4 :: (store (<vscale x 1 x s128>))
+---
+name: clear-kill-in-bundle
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $x0, $z0
+
+ STR_ZXI $z0, $x0, 0 :: (store (<vscale x 1 x s128>))
+ BUNDLE implicit-def $z1, implicit-def $q1, implicit killed $z0 {
+ $z1 = ADD_ZZZ_D $z0, killed $z0
+ }
+ STR_ZXI renamable $z1, $x0, 1 :: (store (<vscale x 1 x s128>))
+
+ RET_ReallyLR
+...
+# CHECK-LABEL: name: clear-kill-in-bundle
+# CHECK: BUNDLE implicit-def $z1, implicit-def $q1, implicit $z0 {
+# CHECK: $z1 = ADD_ZZZ_D $z0, $z0
+# CHECK: }
+# CHECK: STPQi $q0, $q1, $x0, 0 :: (store (<vscale x 1 x s128>))
``````````
</details>
https://github.com/llvm/llvm-project/pull/149177
More information about the llvm-commits
mailing list