[llvm] b2ffc86 - [DAG] getNode() - begin generalizing the (zext (trunc (assertzext x))) -> (assertzext x) fold.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 07:32:54 PDT 2023


Author: Simon Pilgrim
Date: 2023-09-18T15:32:31+01:00
New Revision: b2ffc867ada60fde361c198dfc31d9c90f70e1aa

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

LOG: [DAG] getNode() - begin generalizing the (zext (trunc (assertzext x))) -> (assertzext x) fold.

We'll need to generalize this fold to check for any zero upperbits to address some of the D155472 regressions, but this exposes a number of issues. For now, just use the general MaskedValueIsZero test instead of the assertzext.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 60f4ea7fac47979..7fcd1f4f898911a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5695,8 +5695,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
       SDValue OpOp = N1.getOperand(0);
       if (OpOp.getValueType() == VT) {
         if (OpOp.getOpcode() == ISD::AssertZext && N1->hasOneUse()) {
-          EVT ExtVT = cast<VTSDNode>(OpOp.getOperand(1))->getVT();
-          if (N1.getScalarValueSizeInBits() >= ExtVT.getSizeInBits()) {
+          APInt HiBits = APInt::getBitsSetFrom(VT.getScalarSizeInBits(),
+                                               N1.getScalarValueSizeInBits());
+          if (MaskedValueIsZero(OpOp, HiBits)) {
             transferDbgValues(N1, OpOp);
             return OpOp;
           }


        


More information about the llvm-commits mailing list