[llvm] [DAG] Reassociate (add (add X, Y), X) --> add(shl(X, 1), Y) (PR #162242)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 04:51:07 PDT 2026


================
@@ -2978,6 +2978,17 @@ SDValue DAGCombiner::visitADDLike(SDNode *N) {
     if (SDValue RADD = reassociateOps(ISD::ADD, DL, N0, N1, N->getFlags()))
       return RADD;
 
+    // (X + Y) + X --> Y + (X << 1)
----------------
arsenm wrote:

You wouldn't want this if you have an add3 instruction. It just happens the AMDGPU targets that introduced add3 also introduce lshl_add at the same time 

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


More information about the llvm-commits mailing list