[llvm] [SDAG] Teach FoldConstantArithmetic to match splats inserted into vectors (PR #163984)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 20 03:04:16 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7e7810f10..b283d4ddd 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -7387,9 +7387,9 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
     if (Op.getOpcode() == ISD::INSERT_SUBVECTOR) {
       // match: `insert_subvector undef, (splat X), N2` as `splat X`
       SDValue N0 = Op.getOperand(0);
-      auto* BV = dyn_cast<BuildVectorSDNode>(Op.getOperand(1));
+      auto *BV = dyn_cast<BuildVectorSDNode>(Op.getOperand(1));
       if (!N0.isUndef() || !BV || !(Op = BV->getSplatValue()))
-          return SDValue();
+        return SDValue();
     }
     PreprocessedOps.push_back(Op);
   }
@@ -7413,8 +7413,10 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
       // insert_subvector has been preprocessed, so if it was of the form
       // `insert_subvector undef, (splat X), N2`, it has been replaced with the
       // splat value (X).
-      SDValue ScalarOp = Op.getOpcode() == ISD::INSERT_SUBVECTOR ? Op :
-          Op.getOperand(Op.getOpcode() == ISD::SPLAT_VECTOR ? 0 : I);
+      SDValue ScalarOp =
+          Op.getOpcode() == ISD::INSERT_SUBVECTOR
+              ? Op
+              : Op.getOperand(Op.getOpcode() == ISD::SPLAT_VECTOR ? 0 : I);
       EVT ScalarVT = ScalarOp.getValueType();
 
       // Build vector (integer) scalar operands may need implicit

``````````

</details>


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


More information about the llvm-commits mailing list