From 84750587bf859a048580f7f13b1b2710d0b681fb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 20 Sep 2006 06:29:17 +0000 Subject: [PATCH] Fold the full generality of (any_extend (truncate x)) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30514 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 4e3b572226c..bcbac950f4a 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1858,9 +1858,15 @@ SDOperand DAGCombiner::visitANY_EXTEND(SDNode *N) { N0.getOpcode() == ISD::SIGN_EXTEND) return DAG.getNode(N0.getOpcode(), VT, N0.getOperand(0)); - // fold (aext (truncate x)) -> x iff x size == zext size. - if (N0.getOpcode() == ISD::TRUNCATE && N0.getOperand(0).getValueType() == VT) - return N0.getOperand(0); + // fold (aext (truncate x)) + if (N0.getOpcode() == ISD::TRUNCATE) { + SDOperand TruncOp = N0.getOperand(0); + if (TruncOp.getValueType() == VT) + return TruncOp; // x iff x size == zext size. + if (TruncOp.getValueType() > VT) + return DAG.getNode(ISD::TRUNCATE, VT, TruncOp); + return DAG.getNode(ISD::ANY_EXTEND, VT, TruncOp); + } // fold (aext (load x)) -> (aext (truncate (extload x))) if (N0.getOpcode() == ISD::LOAD && N0.hasOneUse() && (!AfterLegalize||TLI.isOperationLegal(ISD::EXTLOAD, N0.getValueType()))) {