[llvm] 2d4042f - [DAG] visitTRUNCATE - use FoldConstantArithmetic to perform constant folding.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 20 04:14:25 PDT 2023


Author: Simon Pilgrim
Date: 2023-03-20T11:14:14Z
New Revision: 2d4042f4b78ebd4303f558c01b67f8ecabfe47e6

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

LOG: [DAG] visitTRUNCATE - use FoldConstantArithmetic to perform constant folding.

Avoid needing to perform extra isConstantIntBuildVectorOrConstantInt checks

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 548da756c01a..43cb2fde1fe9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14225,11 +14225,8 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
     return DAG.getNode(ISD::TRUNCATE, SDLoc(N), VT, N0.getOperand(0));
 
   // fold (truncate c1) -> c1
-  if (DAG.isConstantIntBuildVectorOrConstantInt(N0)) {
-    SDValue C = DAG.getNode(ISD::TRUNCATE, SDLoc(N), VT, N0);
-    if (C.getNode() != N)
-      return C;
-  }
+  if (SDValue C = DAG.FoldConstantArithmetic(ISD::TRUNCATE, SDLoc(N), VT, {N0}))
+    return C;
 
   // fold (truncate (ext x)) -> (ext x) or (truncate x) or x
   if (N0.getOpcode() == ISD::ZERO_EXTEND ||


        


More information about the llvm-commits mailing list