[llvm] d4af658 - [RISCV] Support multiple memory operands in expandRV32ZdinxStore.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 27 22:14:28 PST 2025
Author: Craig Topper
Date: 2025-01-27T22:10:51-08:00
New Revision: d4af658323c6e2492ca1224930488c390a08c720
URL: https://github.com/llvm/llvm-project/commit/d4af658323c6e2492ca1224930488c390a08c720
DIFF: https://github.com/llvm/llvm-project/commit/d4af658323c6e2492ca1224930488c390a08c720.diff
LOG: [RISCV] Support multiple memory operands in expandRV32ZdinxStore.
TailMerge can create stores with multiple memory operands. We
need to split all of them instead of assuming there is only one.
Added:
llvm/test/CodeGen/RISCV/zdinx-memoperand.ll
Modified:
llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp b/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
index eb3e1a1fe9fd5e..0656bfbef6b35d 100644
--- a/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
@@ -341,15 +341,15 @@ bool RISCVExpandPseudo::expandRV32ZdinxStore(MachineBasicBlock &MBB,
.addImm(MBBI->getOperand(2).getImm() + 4);
}
- if (!MBBI->memoperands_empty()) {
- assert(MBBI->hasOneMemOperand() && "Expected mem operand");
- MachineMemOperand *OldMMO = MBBI->memoperands().front();
- MachineFunction *MF = MBB.getParent();
- MachineMemOperand *MMOLo = MF->getMachineMemOperand(OldMMO, 0, 4);
- MachineMemOperand *MMOHi = MF->getMachineMemOperand(OldMMO, 4, 4);
- MIBLo.setMemRefs(MMOLo);
- MIBHi.setMemRefs(MMOHi);
+ MachineFunction *MF = MBB.getParent();
+ SmallVector<MachineMemOperand *> NewLoMMOs;
+ SmallVector<MachineMemOperand *> NewHiMMOs;
+ for (const MachineMemOperand *MMO : MBBI->memoperands()) {
+ NewLoMMOs.push_back(MF->getMachineMemOperand(MMO, 0, 4));
+ NewHiMMOs.push_back(MF->getMachineMemOperand(MMO, 4, 4));
}
+ MIBLo.setMemRefs(NewLoMMOs);
+ MIBHi.setMemRefs(NewHiMMOs);
MBBI->eraseFromParent();
return true;
@@ -401,15 +401,15 @@ bool RISCVExpandPseudo::expandRV32ZdinxLoad(MachineBasicBlock &MBB,
.add(MBBI->getOperand(2));
}
- if (!MBBI->memoperands_empty()) {
- assert(MBBI->hasOneMemOperand() && "Expected mem operand");
- MachineMemOperand *OldMMO = MBBI->memoperands().front();
- MachineFunction *MF = MBB.getParent();
- MachineMemOperand *MMOLo = MF->getMachineMemOperand(OldMMO, 0, 4);
- MachineMemOperand *MMOHi = MF->getMachineMemOperand(OldMMO, 4, 4);
- MIBLo.setMemRefs(MMOLo);
- MIBHi.setMemRefs(MMOHi);
+ MachineFunction *MF = MBB.getParent();
+ SmallVector<MachineMemOperand *> NewLoMMOs;
+ SmallVector<MachineMemOperand *> NewHiMMOs;
+ for (const MachineMemOperand *MMO : MBBI->memoperands()) {
+ NewLoMMOs.push_back(MF->getMachineMemOperand(MMO, 0, 4));
+ NewHiMMOs.push_back(MF->getMachineMemOperand(MMO, 4, 4));
}
+ MIBLo.setMemRefs(NewLoMMOs);
+ MIBHi.setMemRefs(NewHiMMOs);
MBBI->eraseFromParent();
return true;
diff --git a/llvm/test/CodeGen/RISCV/zdinx-memoperand.ll b/llvm/test/CodeGen/RISCV/zdinx-memoperand.ll
new file mode 100644
index 00000000000000..d618253912470b
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/zdinx-memoperand.ll
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=riscv32 -mattr=+zdinx | FileCheck %s
+
+; This test previously asserted because TailMerge created a PseudoRV32ZdinxSD
+; with 2 memoperands which RISCVExpandPseudo could not handle.
+
+define i32 @foo(double %x, ptr %y, i64 %0, i64 %1, i1 %cmp6.not, ptr %arrayidx13, ptr %arrayidx20) {
+; CHECK-LABEL: foo:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: andi a0, a7, 1
+; CHECK-NEXT: beqz a0, .LBB0_2
+; CHECK-NEXT: # %bb.1: # %if.else
+; CHECK-NEXT: lw a0, 4(sp)
+; CHECK-NEXT: j .LBB0_3
+; CHECK-NEXT: .LBB0_2: # %if.then7
+; CHECK-NEXT: lw a0, 0(sp)
+; CHECK-NEXT: .LBB0_3: # %common.ret
+; CHECK-NEXT: fcvt.d.w a2, zero
+; CHECK-NEXT: sw a2, 0(a0)
+; CHECK-NEXT: sw a3, 4(a0)
+; CHECK-NEXT: li a0, 0
+; CHECK-NEXT: ret
+entry:
+ br i1 %cmp6.not, label %if.else, label %if.then7
+
+common.ret: ; preds = %if.else, %if.then7
+ ret i32 0
+
+if.then7: ; preds = %entry
+ store double 0.000000e+00, ptr %arrayidx13, align 8
+ br label %common.ret
+
+if.else: ; preds = %entry
+ store double 0.000000e+00, ptr %arrayidx20, align 8
+ br label %common.ret
+}
+
More information about the llvm-commits
mailing list