[llvm] [SPARC] Use hardware byteswapper when we have V9 (PR #191720)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 05:45:45 PDT 2026
================
@@ -3001,6 +3004,37 @@ static SDValue LowerF128Load(SDValue Op, SelectionDAG &DAG)
return DAG.getMergeValues(Ops, dl);
}
+SDValue SparcTargetLowering::LowerBSWAP(SDValue Op, SelectionDAG &DAG) const {
+ // We don't have an in-register bswap, so expand bswap(x) into
+ // load(store-swapped(x)). The reason the swap is done during the store is
+ // that on some implementations (mainly older ones) ASI-tagged memory
+ // operations are not pipelined, and generally stores finish faster than
+ // loads.
+
+ MachineFunction &MF = DAG.getMachineFunction();
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+ auto PtrVT = getPointerTy(DAG.getDataLayout());
+ SDValue Chain = DAG.getEntryNode();
+ bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
+ SDLoc DL(Op);
+
+ SDValue BSwapOp = Op.getOperand(0);
+ EVT BSwapVT = BSwapOp.getValueType();
+
+ // Create a stack object to serve as temporary storage.
+ int BSwapFI = MFI.CreateStackObject(BSwapVT.getStoreSize(), Align(8), false);
+ SDValue BSwapPtr = DAG.getFrameIndex(BSwapFI, PtrVT);
+
+ // Store-swap the value, then load it back.
+ SDValue Ops[] = {Chain, BSwapOp, BSwapPtr, DAG.getValueType(BSwapVT)};
+ SDValue SwappedMem = DAG.getMemIntrinsicNode(
----------------
s-barannikov wrote:
(nit) The returned value isn't "swapped memory", it is a chain, so maybe just `ST` (for store)? I think it is most common naming.
https://github.com/llvm/llvm-project/pull/191720
More information about the llvm-commits
mailing list