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

via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 18 21:10:19 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);
----------------
koachan wrote:

> truncate down to MemVT instead of hardcoding an i32?

Oh wait no, it has to be an i32 I think. `SparcTargetLowering::SparcTargetLowering` only defines operations on i32 and i64 so putting an i16 or other types in there would cause instruction selection to fail too.

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


More information about the llvm-commits mailing list