[llvm] [SPARC] Don't combine misaligned memory ops with BSWAP (PR #206345)

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 4 23:19:45 PDT 2026


================
@@ -3266,9 +3266,14 @@ SDValue SparcTargetLowering::PerformBSWAPCombine(SDNode *N,
   EVT VT = N->getValueType(0);
   bool IsLittleEndian = DAG.getDataLayout().isLittleEndian();
 
-  // Turn BSWAP (LOAD) -> ld*a #ASI_P(_L) on V9.
-  if (Subtarget->isV9() && ISD::isNormalLoad(Op.getNode()) &&
-      Op.getNode()->hasOneUse() &&
+  LoadSDNode *LN = dyn_cast<LoadSDNode>(Op.getNode());
+  bool IsAlignedLoad =
+      LN && ISD::isNormalLoad(Op.getNode()) &&
+      allowsMemoryAccessForAlignment(*DAG.getContext(), DAG.getDataLayout(), VT,
----------------
koachan wrote:

> the type of the loaded/stored value and the type of the memory location

In case the two differs the correct one to pick is the memory location's type, I think?
Cus the alignment check would be done in the memory-sized value anyway (e.g in extending load using `ldsha` 2-byte alignment is enough even though the result will be sign-extended 8 byte quantity)

https://github.com/llvm/llvm-project/pull/206345


More information about the llvm-commits mailing list