[PATCH] D34726: AMDGPU/SI: Don not insert an instruction into worklist twice in movetovalu

Changpeng Fang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 16:39:42 PDT 2017


cfang created this revision.
Herald added subscribers: t-tye, tpr, dstuttard, yaxunl, nhaehnle, wdng, kzhuravl.

In movetovalu, when we process an instruction in the worklist, we may delete/modify the instruction. So putting an 
instruction in the worklist may result in handling a deleted/modified instruction, and thus cause trouble.


https://reviews.llvm.org/D34726

Files:
  lib/Target/AMDGPU/SIInstrInfo.cpp
  test/CodeGen/AMDGPU/move-to-valu-worklist.ll


Index: test/CodeGen/AMDGPU/move-to-valu-worklist.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/move-to-valu-worklist.ll
@@ -0,0 +1,31 @@
+; RUN: llc -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck %s
+
+; CHECK-LABEL: {{^}}in_worklist_once:
+; CHECK: buffer_load_dword
+; CHECK: BB0_1:
+; CHECK: s_branch BB0_1
+define amdgpu_kernel void @in_worklist_once() #0 {
+bb:
+  %tmp = load i64, i64* undef
+  br label %bb1
+
+bb1:                                              ; preds = %bb1, %bb
+  %tmp2 = phi i64 [ undef, %bb ], [ %tmp16, %bb1 ]
+  %tmp3 = phi i64 [ %tmp, %bb ], [ undef, %bb1 ]
+  %tmp4 = xor i64 0, %tmp2
+  %tmp5 = xor i64 %tmp4, 0
+  %tmp6 = xor i64 %tmp5, 0
+  %tmp7 = xor i64 %tmp6, 0
+  %tmp8 = xor i64 0, %tmp7
+  %tmp9 = xor i64 0, %tmp3
+  %tmp10 = xor i64 0, %tmp8
+  %tmp11 = shl i64 %tmp10, 14
+  %tmp12 = lshr i64 %tmp10, 50
+  %tmp13 = or i64 %tmp11, %tmp12
+  %tmp14 = xor i64 0, %tmp9
+  %tmp15 = and i64 %tmp9, %tmp13
+  %tmp16 = xor i64 %tmp15, %tmp14
+  br label %bb1
+}
+
+attributes #0 = { nounwind }
Index: lib/Target/AMDGPU/SIInstrInfo.cpp
===================================================================
--- lib/Target/AMDGPU/SIInstrInfo.cpp
+++ lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -3856,7 +3856,9 @@
          E = MRI.use_end(); I != E;) {
     MachineInstr &UseMI = *I->getParent();
     if (!canReadVGPR(UseMI, I.getOperandNo())) {
-      Worklist.push_back(&UseMI);
+      // Do not add to worklist twice!
+      if(Worklist.end() == llvm::find(Worklist, &MI))
+        Worklist.push_back(&UseMI);
 
       do {
         ++I;
@@ -3941,7 +3943,9 @@
       return;
 
     if (MI.findRegisterUseOperandIdx(AMDGPU::SCC) != -1)
-      Worklist.push_back(&MI);
+      // Do not add to worklist twice!
+      if(Worklist.end() == llvm::find(Worklist, &MI))
+        Worklist.push_back(&MI);
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34726.104310.patch
Type: text/x-patch
Size: 1918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170627/29750283/attachment.bin>


More information about the llvm-commits mailing list