[PATCH] D93174: [amdgpu] Fix a crash case when `V_CNDMASK` could be simplified.
Michael Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 12 21:41:04 PST 2020
hliao created this revision.
hliao added reviewers: rampitec, arsenm.
Herald added subscribers: kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
hliao requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
- Once an instruction is simplified, foldable candidates from it should be invalidated or skipped as the operand index is no longer valid.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D93174
Files:
llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
llvm/test/CodeGen/AMDGPU/fold-cndmask-wave32.mir
Index: llvm/test/CodeGen/AMDGPU/fold-cndmask-wave32.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/fold-cndmask-wave32.mir
@@ -0,0 +1,20 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -march=amdgcn -mcpu=gfx1030 -run-pass si-fold-operands -verify-machineinstrs -o - %s | FileCheck %s
+
+---
+name: fold_cndmask
+tracksRegLiveness: true
+registers:
+body: |
+ bb.0.entry:
+ ; CHECK-LABEL: name: fold_cndmask
+ ; CHECK: [[DEF:%[0-9]+]]:sreg_32_xm0_xexec = IMPLICIT_DEF
+ ; CHECK: [[S_MOV_B32_:%[0-9]+]]:sreg_32 = S_MOV_B32 0
+ ; CHECK: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+ ; CHECK: [[COPY:%[0-9]+]]:vgpr_32 = COPY [[S_MOV_B32_]]
+ %0:sreg_32_xm0_xexec = IMPLICIT_DEF
+ %1:sreg_32 = S_MOV_B32 0
+ %2:vgpr_32 = COPY %1:sreg_32
+ %3:vgpr_32 = V_CNDMASK_B32_e64 0, %1:sreg_32, 0, %2:vgpr_32, %0:sreg_32_xm0_xexec, implicit $exec
+
+...
Index: llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
+++ llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
@@ -1257,8 +1257,11 @@
for (MachineInstr *Copy : CopiesToReplace)
Copy->addImplicitDefUseOperands(*MF);
+ SmallPtrSet<MachineInstr *, 16> Folded;
for (FoldCandidate &Fold : FoldList) {
assert(!Fold.isReg() || Fold.OpToFold);
+ if (Folded.count(Fold.UseMI))
+ continue;
if (Fold.isReg() && Fold.OpToFold->getReg().isVirtual()) {
Register Reg = Fold.OpToFold->getReg();
MachineInstr *DefMI = Fold.OpToFold->getParent();
@@ -1278,7 +1281,8 @@
LLVM_DEBUG(dbgs() << "Folded source from " << MI << " into OpNo "
<< static_cast<int>(Fold.UseOpNo) << " of "
<< *Fold.UseMI << '\n');
- tryFoldInst(TII, Fold.UseMI);
+ if (tryFoldInst(TII, Fold.UseMI))
+ Folded.insert(Fold.UseMI);
} else if (Fold.isCommuted()) {
// Restoring instruction's original operand order if fold has failed.
TII->commuteInstruction(*Fold.UseMI, false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93174.311429.patch
Type: text/x-patch
Size: 2197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201213/bd27393d/attachment.bin>
More information about the llvm-commits
mailing list