diff options
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 71a175d..649a310 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6422,6 +6422,20 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, if (N1.isUndef()) // sext(undef) = 0, because the top bits will all be the same. return getConstant(0, DL, VT); + + // Skip unnecessary sext_inreg pattern: + // (sext (trunc x)) -> x iff the upper bits are all signbits. + if (OpOpcode == ISD::TRUNCATE) { + SDValue OpOp = N1.getOperand(0); + if (OpOp.getValueType() == VT) { + unsigned NumSignExtBits = + VT.getScalarSizeInBits() - N1.getScalarValueSizeInBits(); + if (ComputeNumSignBits(OpOp) > NumSignExtBits) { + transferDbgValues(N1, OpOp); + return OpOp; + } + } + } break; case ISD::ZERO_EXTEND: assert(VT.isInteger() && N1.getValueType().isInteger() && |