[llvm] [RISCV] Support isel for Zacas for 2*XLen types. (PR #77814)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 11:07:41 PST 2024
================
@@ -11237,13 +11243,86 @@ static SDValue customLegalizeToWOpWithSExt(SDNode *N, SelectionDAG &DAG) {
return DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, NewRes);
}
+// Create an even/odd pair of X registers holding integer value V.
+static SDValue createGPRPairNode(SelectionDAG &DAG, SDValue V, MVT VT,
+ MVT SubRegVT) {
+ SDLoc DL(V.getNode());
+ auto [VLo, VHi] = DAG.SplitScalar(V, DL, SubRegVT, SubRegVT);
+ SDValue RegClass =
+ DAG.getTargetConstant(RISCV::GPRPairRegClassID, DL, MVT::i32);
+ SDValue SubReg0 = DAG.getTargetConstant(RISCV::sub_gpr_even, DL, MVT::i32);
+ SDValue SubReg1 = DAG.getTargetConstant(RISCV::sub_gpr_odd, DL, MVT::i32);
+ const SDValue Ops[] = {RegClass, VLo, SubReg0, VHi, SubReg1};
+ return SDValue(
+ DAG.getMachineNode(TargetOpcode::REG_SEQUENCE, DL, MVT::Untyped, Ops), 0);
+}
+
+static void ReplaceCMP_SWAP_2XLenResults(SDNode *N,
+ SmallVectorImpl<SDValue> &Results,
+ SelectionDAG &DAG,
+ const RISCVSubtarget &Subtarget) {
+ MVT VT = N->getSimpleValueType(0);
+ assert(N->getValueType(0) == (Subtarget.is64Bit() ? MVT::i128 : MVT::i64) &&
+ "AtomicCmpSwap on types less than 2*XLen should be legal");
+ assert(Subtarget.hasStdExtZacas());
+ MVT XLenVT = Subtarget.getXLenVT();
+
+ SDValue Ops[] = {
+ createGPRPairNode(DAG, N->getOperand(2), VT, XLenVT), // Compare value
+ N->getOperand(1), // Ptr
+ createGPRPairNode(DAG, N->getOperand(3), VT, XLenVT), // Store value
+ N->getOperand(0), // Chain in
+ };
+
+ MachineMemOperand *MemOp = cast<MemSDNode>(N)->getMemOperand();
+
+ bool Is64Bit = Subtarget.is64Bit();
+ unsigned Opcode;
+ if (Subtarget.hasStdExtZtso()) {
+ Opcode = Subtarget.is64Bit() ? RISCV::AMOCAS_Q : RISCV::AMOCAS_D_RV32;
----------------
dtcxzyw wrote:
```suggestion
Opcode = Is64Bit ? RISCV::AMOCAS_Q : RISCV::AMOCAS_D_RV32;
```
https://github.com/llvm/llvm-project/pull/77814
More information about the llvm-commits
mailing list