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

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 4 00:52:17 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,
----------------
s-barannikov wrote:

The alignment check ould be as simple as this:
https://github.com/llvm/llvm-project/blob/041262ddff11fab6b84e3542596d0d8a5b593bd2/llvm/lib/CodeGen/TargetLoweringBase.cpp#L2163
where `Alignment` is `MMO.getAlign()`.

But I guess we can also compare the alignment agains VT size (to address that TODO comment by the link).


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


More information about the llvm-commits mailing list