[llvm] [AArch64] Only clear kill flags if necessary when merging str (PR #69680)

Zhaoxuan Jiang via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 01:38:43 PDT 2023


================
@@ -997,8 +997,17 @@ AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
       //   STRWui %w0, ...
       //   USE %w1
       //   STRWui kill %w1  ; need to clear kill flag when moving STRWui upwards
-      RegOp0.setIsKill(false);
-      RegOp1.setIsKill(false);
+      for (auto It = std::next(I);
+           It != Paired && (RegOp0.isKill() || RegOp1.isKill()); ++It) {
+        auto ClearKill = [](MachineInstr &MI, MachineOperand &MOP,
+                            const TargetRegisterInfo *TRI) {
+          Register Reg = MOP.getReg();
+          if (MI.readsRegister(Reg, TRI))
+            MOP.setIsKill(false);
+        };
+        ClearKill(*It, RegOp0, TRI);
----------------
nocchijiang wrote:

@MatzeB I am wondering if clearing flags for both `RegOp0` and `RegOp1` is necessary. Take the sample you wrote above for example, the merge should not change the flags on `w0` because the read/write order of `w0` is not modified. Correct me if I am wrong.

https://github.com/llvm/llvm-project/pull/69680


More information about the llvm-commits mailing list