[llvm] Remove unneeded work from machine memset (PR #65672)

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 13:58:17 PDT 2023


https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/65672:

I noticed some unnecessary computation in aarch64.

The memset intrinsics have no source pointer, so don't construct that operand.

[originally posted as https://reviews.llvm.org/D159444, but let's try this exciting new workflow]

>From 25f1a48da4a1901852a9f966fe441e0039fe86d7 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Mon, 4 Sep 2023 17:46:39 -0400
Subject: [PATCH] Remove unneeded work from machine memset

The memset intrinsics have no source pointer, so don't construct that
operand.
---
 .../AArch64/AArch64SelectionDAGInfo.cpp       | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp b/llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp
index 677797a6797bb69..10d2e768cb29abe 100644
--- a/llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SelectionDAGInfo.cpp
@@ -46,21 +46,16 @@ SDValue AArch64SelectionDAGInfo::EmitMOPS(AArch64ISD::NodeType SDOpcode,
     }
   }();
 
-  MachineMemOperand::Flags Flags = MachineMemOperand::MOStore;
-  if (isVolatile)
-    Flags |= MachineMemOperand::MOVolatile;
-  if (!IsSet)
-    Flags |= MachineMemOperand::MOLoad;
-
   MachineFunction &MF = DAG.getMachineFunction();
 
+  auto Vol =
+      isVolatile ? MachineMemOperand::MOVolatile : MachineMemOperand::MONone;
+  auto DstFlags = MachineMemOperand::MOStore | Vol;
   auto *DstOp =
-      MF.getMachineMemOperand(DstPtrInfo, Flags, ConstSize, Alignment);
-  auto *SrcOp =
-      MF.getMachineMemOperand(SrcPtrInfo, Flags, ConstSize, Alignment);
+      MF.getMachineMemOperand(DstPtrInfo, DstFlags, ConstSize, Alignment);
 
   if (IsSet) {
-    // Extend value to i64 if required
+    // Extend value to i64, if required.
     if (SrcOrValue.getValueType() != MVT::i64)
       SrcOrValue = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, SrcOrValue);
     SDValue Ops[] = {Dst, Size, SrcOrValue, Chain};
@@ -72,6 +67,10 @@ SDValue AArch64SelectionDAGInfo::EmitMOPS(AArch64ISD::NodeType SDOpcode,
     SDValue Ops[] = {Dst, SrcOrValue, Size, Chain};
     const EVT ResultTys[] = {MVT::i64, MVT::i64, MVT::i64, MVT::Other};
     MachineSDNode *Node = DAG.getMachineNode(MachineOpcode, DL, ResultTys, Ops);
+
+    auto SrcFlags = MachineMemOperand::MOLoad | Vol;
+    auto *SrcOp =
+        MF.getMachineMemOperand(SrcPtrInfo, SrcFlags, ConstSize, Alignment);
     DAG.setNodeMemRefs(Node, {DstOp, SrcOp});
     return SDValue(Node, 3);
   }



More information about the llvm-commits mailing list