[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 22:17:22 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:

That looks correct.
Note that loads and stores have two types, the type of the loaded/stored value and the type of the memory location. They may be different in the case of extending/truncating operation. isNormalLoad should ensure they are the same, so you can check the size of either of them. Not sure which one is logically correct.

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


More information about the llvm-commits mailing list