From: Chris Lattner Date: Wed, 7 Dec 2005 07:11:03 +0000 (+0000) Subject: Teach the dag combiner to turn a truncate/sign_extend pair into a sextinreg X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b14ab8a10d7955501ec80b247b2510bbd2511b12;p=oota-llvm.git Teach the dag combiner to turn a truncate/sign_extend pair into a sextinreg when the types match up. This allows the X86 backend to compile: sbyte %toggle_value(sbyte* %tmp.1) { %tmp.2 = load sbyte* %tmp.1 ret sbyte %tmp.2 } to this: _toggle_value: mov %EAX, DWORD PTR [%ESP + 4] movsx %EAX, BYTE PTR [%EAX] ret instead of this: _toggle_value: mov %EAX, DWORD PTR [%ESP + 4] movsx %EAX, BYTE PTR [%EAX] movsx %EAX, %AL ret noticed in Shootout/objinst. -Chris git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24630 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 6cd66c7c19c..b7f6853f74c 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1546,6 +1546,10 @@ SDOperand DAGCombiner::visitSIGN_EXTEND(SDNode *N) { // fold (sext (sextload x)) -> (sextload x) if (N0.getOpcode() == ISD::SEXTLOAD && VT == N0.getValueType()) return N0; + // fold (sext (truncate x)) -> (sextinreg x) iff x size == sext size. + if (N0.getOpcode() == ISD::TRUNCATE && N0.getOperand(0).getValueType() == VT) + return DAG.getNode(ISD::SIGN_EXTEND_INREG, VT, N0.getOperand(0), + DAG.getValueType(N0.getValueType())); // fold (sext (load x)) -> (sextload x) if (N0.getOpcode() == ISD::LOAD && N0.hasOneUse()) { SDOperand ExtLoad = DAG.getExtLoad(ISD::SEXTLOAD, VT, N0.getOperand(0),