[llvm] a09a3c6 - Revert rG8e05ac0a510c - "[DAGCombine] visitTRUNCATE - remove GetDemandedBits call"

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat May 2 12:09:15 PDT 2020


Author: Simon Pilgrim
Date: 2020-05-02T20:08:33+01:00
New Revision: a09a3c6d3e0fe76c4b7e6298f22f4dea2825f35a

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

LOG: Revert rG8e05ac0a510c - "[DAGCombine] visitTRUNCATE - remove GetDemandedBits call"

Causing buildbot failures

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 3c8d1f3c7f36..d8c6b51db9c6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -11112,6 +11112,18 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
     }
   }
 
+  // See if we can simplify the input to this truncate through knowledge that
+  // only the low bits are being used.
+  // For example "trunc (or (shl x, 8), y)" // -> trunc y
+  // Currently we only perform this optimization on scalars because vectors
+  // may have 
diff erent active low bits.
+  if (!VT.isVector()) {
+    APInt Mask =
+        APInt::getLowBitsSet(N0.getValueSizeInBits(), VT.getSizeInBits());
+    if (SDValue Shorter = DAG.GetDemandedBits(N0, Mask))
+      return DAG.getNode(ISD::TRUNCATE, SDLoc(N), VT, Shorter);
+  }
+
   // fold (truncate (load x)) -> (smaller load x)
   // fold (truncate (srl (load x), c)) -> (smaller load (x+c/evtbits))
   if (!LegalTypes || TLI.isTypeDesirableForOp(N0.getOpcode(), VT)) {


        


More information about the llvm-commits mailing list