[llvm] 4d7da0e - [DAG] Cleanup the (zext (shl (zext x), cst)) -> (shl (zext x), cst) fold. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 12 08:01:51 PDT 2023
Author: Simon Pilgrim
Date: 2023-03-12T15:01:33Z
New Revision: 4d7da0e7116a1247fefa732b96abf87f0f17c442
URL: https://github.com/llvm/llvm-project/commit/4d7da0e7116a1247fefa732b96abf87f0f17c442
DIFF: https://github.com/llvm/llvm-project/commit/4d7da0e7116a1247fefa732b96abf87f0f17c442.diff
LOG: [DAG] Cleanup the (zext (shl (zext x), cst)) -> (shl (zext x), cst) fold. NFC.
Preliminary cleanup before adding some additional legality and value tracking handling.
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 c78b9dde780a..ce4028726721 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -13398,30 +13398,31 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
}
// (zext (shl (zext x), cst)) -> (shl (zext x), cst)
- if ((N0.getOpcode() == ISD::SHL || N0.getOpcode() == ISD::SRL) &&
- isa<ConstantSDNode>(N0.getOperand(1)) &&
- N0.getOperand(0).getOpcode() == ISD::ZERO_EXTEND &&
- N0.hasOneUse()) {
+ if (N0.getOpcode() == ISD::SHL || N0.getOpcode() == ISD::SRL) {
+ SDValue ShVal = N0.getOperand(0);
SDValue ShAmt = N0.getOperand(1);
- if (N0.getOpcode() == ISD::SHL) {
- SDValue InnerZExt = N0.getOperand(0);
- // If the original shl may be shifting out bits, do not perform this
- // transformation.
- unsigned KnownZeroBits = InnerZExt.getValueSizeInBits() -
- InnerZExt.getOperand(0).getValueSizeInBits();
- if (cast<ConstantSDNode>(ShAmt)->getAPIntValue().ugt(KnownZeroBits))
- return SDValue();
- }
+ if (auto *ShAmtC = dyn_cast<ConstantSDNode>(ShAmt)) {
+ if (ShVal.getOpcode() == ISD::ZERO_EXTEND && N0.hasOneUse()) {
+ if (N0.getOpcode() == ISD::SHL) {
+ // If the original shl may be shifting out bits, do not perform this
+ // transformation.
+ // TODO: Add MaskedValueIsZero check.
+ unsigned KnownZeroBits = ShVal.getValueSizeInBits() -
+ ShVal.getOperand(0).getValueSizeInBits();
+ if (ShAmtC->getAPIntValue().ugt(KnownZeroBits))
+ return SDValue();
+ }
- SDLoc DL(N);
+ SDLoc DL(N);
- // Ensure that the shift amount is wide enough for the shifted value.
- if (Log2_32_Ceil(VT.getSizeInBits()) > ShAmt.getValueSizeInBits())
- ShAmt = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, ShAmt);
+ // Ensure that the shift amount is wide enough for the shifted value.
+ if (Log2_32_Ceil(VT.getSizeInBits()) > ShAmt.getValueSizeInBits())
+ ShAmt = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, ShAmt);
- return DAG.getNode(N0.getOpcode(), DL, VT,
- DAG.getNode(ISD::ZERO_EXTEND, DL, VT, N0.getOperand(0)),
- ShAmt);
+ return DAG.getNode(N0.getOpcode(), DL, VT,
+ DAG.getNode(ISD::ZERO_EXTEND, DL, VT, ShVal), ShAmt);
+ }
+ }
}
if (SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
More information about the llvm-commits
mailing list