[llvm] [SPARC] Emit a TRUNCATE when combining truncating BSWAP-STOREs (PR #210483)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 09:57:32 PDT 2026


================
@@ -3333,6 +3333,9 @@ SDValue SparcTargetLowering::PerformSTORECombine(SDNode *N,
       unsigned Shift = VT.getSizeInBits() - MemVT.getSizeInBits();
       BSwapOp = DAG.getNode(ISD::SRL, DL, VT, BSwapOp,
                             DAG.getShiftAmountConstant(Shift, VT, DL));
+      // Need to truncate if this is a bswap of i64 stored as i32/i16.
+      if (VT == MVT::i64)
+        BSwapOp = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, BSwapOp);
----------------
s-barannikov wrote:

> Removing the `TRUNCATE` and adding i64->i32 and i64->i16 patterns seem to work too. Should I go with that instead?

If that works, I'd prefer the patterns over inserting a TRUNCATE that creates an invalid DAG in some cases (even though it happens to work somehow).

> I'm thinking that the extra patterns would match the already defined i32->i16 one...

I'm not sure I undersnant what you're trying to say?..


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


More information about the llvm-commits mailing list