Skip to content

Commit

Permalink
[DAGCombiner] Remove (sra (shl X, C), C) if X has more than C sign bits.
Browse files Browse the repository at this point in the history
If sext_inreg is supported, we will turn this into sext_inreg. That
will then remove it if there are enough sign bits. But if sext_inreg
isn't supported, we can still remove the shift pair based on sign
bits.

Split from D95890.
  • Loading branch information
topperc authored and pull[bot] committed Jan 31, 2024
1 parent 37b2983 commit 9510019
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 126 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Expand Up @@ -8368,6 +8368,10 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
TargetLowering::Legal)
return DAG.getNode(ISD::SIGN_EXTEND_INREG, SDLoc(N), VT,
N0.getOperand(0), DAG.getValueType(ExtVT));
// Even if we can't convert to sext_inreg, we might be able to remove
// this shift pair if the input is already sign extended.
if (DAG.ComputeNumSignBits(N0.getOperand(0)) > N1C->getZExtValue())
return N0.getOperand(0);
}

// fold (sra (sra x, c1), c2) -> (sra x, (add c1, c2))
Expand Down

0 comments on commit 9510019

Please sign in to comment.