[PATCH] D126754: [MachineSink] Clear kill flags on operands outside loop

Carl Ritson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 31 23:10:34 PDT 2022


critson created this revision.
critson added reviewers: jonpa, craig.topper, fhahn, MatzeB.
Herald added subscribers: StephenFan, asbirlea, hiraditya.
Herald added a project: All.
critson requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If an instruction is sunk into a loop then any kill flags on
operands declared outside the loop must be cleared as these
will be live for all loop iterations.

Fixes #46827


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126754

Files:
  llvm/lib/CodeGen/MachineSink.cpp
  llvm/test/CodeGen/SystemZ/machinelicm-sunk-kill-flags.ll


Index: llvm/test/CodeGen/SystemZ/machinelicm-sunk-kill-flags.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/SystemZ/machinelicm-sunk-kill-flags.ll
@@ -0,0 +1,23 @@
+; RUN: llc -mtriple=s390x-linux-gnu -O3 -consthoist-gep -sink-insts-to-avoid-spills -verify-machineinstrs -o /dev/null %s
+; REQUIRES: asserts
+
+; Test that verification passes after MachineLICM.
+
+%0 = type <{ i32, [3 x i8] }>
+ at b = external dso_local global [1 x %0], align 2
+
+define dso_local void @c() local_unnamed_addr #0 {
+bb:
+  br label %bb1
+
+bb1:                                              ; preds = %bb1, %bb
+  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 undef, ptr align 1 getelementptr inbounds ([1 x %0], ptr @b, i64 7, i64 0), i64 7, i1 true)
+  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 undef, ptr align 1 getelementptr inbounds ([1 x %0], ptr @b, i64 7, i64 0), i64 7, i1 true)
+  br label %bb1
+}
+
+; Function Attrs: argmemonly nofree nounwind willreturn
+declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1
+
+attributes #0 = { "target-features"="+transactional-execution,+vector,+vector-enhancements-1,+vector-enhancements-2" }
+attributes #1 = { argmemonly nofree nounwind willreturn }
Index: llvm/lib/CodeGen/MachineSink.cpp
===================================================================
--- llvm/lib/CodeGen/MachineSink.cpp
+++ llvm/lib/CodeGen/MachineSink.cpp
@@ -1287,6 +1287,19 @@
   SinkBlock->splice(SinkBlock->SkipPHIsAndLabels(SinkBlock->begin()), Preheader,
                     I);
 
+  // Clear any kill flags on uses defined outside cycle
+  for (MachineOperand &MO : I.operands()) {
+    if (!MO.isReg() || !MO.isUse() || !MO.isKill())
+      continue;
+
+    for (const MachineInstr &MI : MRI->def_instructions(MO.getReg())) {
+      if (!Cycle->contains(MI.getParent())) {
+        MO.setIsKill(false);
+        break;
+      }
+    }
+  }
+
   // The instruction is moved from its basic block, so do not retain the
   // debug information.
   assert(!I.isDebugInstr() && "Should not sink debug inst");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126754.433288.patch
Type: text/x-patch
Size: 2169 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220601/e8ae992f/attachment.bin>


More information about the llvm-commits mailing list