[llvm] a6a788b - [DAG] foldBinOpIntoSelect - use FoldConstantArithmetic instead of getNode() + constant check.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 05:59:37 PDT 2023


Author: Simon Pilgrim
Date: 2023-03-21T12:59:16Z
New Revision: a6a788bdfb39cbf66e7196a39785d848ce714338

URL: https://github.com/llvm/llvm-project/commit/a6a788bdfb39cbf66e7196a39785d848ce714338
DIFF: https://github.com/llvm/llvm-project/commit/a6a788bdfb39cbf66e7196a39785d848ce714338.diff

LOG: [DAG] foldBinOpIntoSelect - use FoldConstantArithmetic instead of getNode() + constant check.

This prevents unused nodes from being created if the constant check fails.

Noticed while triaging D127115 regressions

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 43cb2fde1fe9f..5a331ceb96d64 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2483,16 +2483,14 @@ SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) {
     // constant. Eliminate the binop by pulling the constant math into the
     // select. Example: add (select Cond, CT, CF), CBO --> select Cond, CT +
     // CBO, CF + CBO
-    NewCT = SelOpNo ? DAG.getNode(BinOpcode, DL, VT, CBO, CT)
-                    : DAG.getNode(BinOpcode, DL, VT, CT, CBO);
-    if (!NewCT.isUndef() && !isConstantOrConstantVector(NewCT, true) &&
-        !DAG.isConstantFPBuildVectorOrConstantFP(NewCT))
+    NewCT = SelOpNo ? DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CBO, CT})
+                    : DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CT, CBO});
+    if (!NewCT)
       return SDValue();
 
-    NewCF = SelOpNo ? DAG.getNode(BinOpcode, DL, VT, CBO, CF)
-                    : DAG.getNode(BinOpcode, DL, VT, CF, CBO);
-    if (!NewCF.isUndef() && !isConstantOrConstantVector(NewCF, true) &&
-        !DAG.isConstantFPBuildVectorOrConstantFP(NewCF))
+    NewCF = SelOpNo ? DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CBO, CF})
+                    : DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CF, CBO});
+    if (!NewCF)
       return SDValue();
   }
 


        


More information about the llvm-commits mailing list