[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 08:11:25 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:

We currently have these patterns for i64 argument:
```
  def : Pat<(SPstorelittle i32:$val, ForceADDRrr:$dst, i16), (STHArr ForceADDRrr:$dst, $val, 0x88)>;
  def : Pat<(SPstorelittle i32:$val, ForceADDRrr:$dst, i32), (STArr  ForceADDRrr:$dst, $val, 0x88)>;
  def : Pat<(SPstorelittle i64:$val, ForceADDRrr:$dst, i64), (STXArr ForceADDRrr:$dst, $val, 0x88)>;
```
(same for big).

How come this works in i64 -> i32 truncation case?


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


More information about the llvm-commits mailing list