[llvm] 8c99cef - [DAG] Remove SelectionDAG::GetDemandedBits and use SimplifyMultipleUseDemandedBits directly.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 09:06:31 PDT 2022
Author: Simon Pilgrim
Date: 2022-07-28T17:03:44+01:00
New Revision: 8c99cef1e7525db1e22e0aa20df35ef11236f750
URL: https://github.com/llvm/llvm-project/commit/8c99cef1e7525db1e22e0aa20df35ef11236f750
DIFF: https://github.com/llvm/llvm-project/commit/8c99cef1e7525db1e22e0aa20df35ef11236f750.diff
LOG: [DAG] Remove SelectionDAG::GetDemandedBits and use SimplifyMultipleUseDemandedBits directly.
GetDemandedBits is mainly a wrapper around SimplifyMultipleUseDemandedBits now, and is only used by DAGCombiner::visitSTORE so I've moved all remaining functionality there.
visitSTORE was making use of this to 'simplify' constants for a trunc-store. Just removing this code left to a mixture of regressions and gains - it came down to whether a target preferred a sign or zero extended constant for materialization/truncation. I've just moved the code over for now, but a next step would be to move this to targetShrinkDemandedConstant, but some targets that override the method expect a basic binop, and might react badly to a store node.....
Added:
Modified:
llvm/include/llvm/CodeGen/SelectionDAG.h
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 1169e0116ec8e..c22c987fc6665 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -1856,14 +1856,6 @@ class SelectionDAG {
SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond,
const SDLoc &dl);
- /// See if the specified operand can be simplified with the knowledge that
- /// only the bits specified by DemandedBits are used. If so, return the
- /// simpler operand, otherwise return a null SDValue.
- ///
- /// (This exists alongside SimplifyDemandedBits because GetDemandedBits can
- /// simplify nodes with multiple uses more aggressively.)
- SDValue GetDemandedBits(SDValue V, const APInt &DemandedBits);
-
/// Return true if the sign bit of Op is known to be zero.
/// We use this predicate to simplify operations downstream.
bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 2b42a4f0df6b4..502f33a8dce70 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -19057,9 +19057,24 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) {
// Otherwise, see if we can simplify the input to this truncstore with
// knowledge that only the low bits are being used. For example:
// "truncstore (or (shl x, 8), y), i8" -> "truncstore y, i8"
- if (SDValue Shorter = DAG.GetDemandedBits(Value, TruncDemandedBits))
+ if (SDValue Shorter =
+ TLI.SimplifyMultipleUseDemandedBits(Value, TruncDemandedBits, DAG))
return DAG.getTruncStore(Chain, SDLoc(N), Shorter, Ptr, ST->getMemoryVT(),
ST->getMemOperand());
+
+ // If we're storing a truncated constant, see if we can simplify it.
+ // TODO: Move this to targetShrinkDemandedConstant?
+ if (auto *Cst = dyn_cast<ConstantSDNode>(Value))
+ if (!Cst->isOpaque()) {
+ const APInt &CValue = Cst->getAPIntValue();
+ APInt NewVal = CValue & TruncDemandedBits;
+ if (NewVal != CValue) {
+ SDValue Shorter =
+ DAG.getConstant(NewVal, SDLoc(N), Value.getValueType());
+ return DAG.getTruncStore(Chain, SDLoc(N), Shorter, Ptr,
+ ST->getMemoryVT(), ST->getMemOperand());
+ }
+ }
}
// If this is a load followed by a store to the same location, then the store
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 357ff271bc2a2..08cec4f03ba70 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2459,33 +2459,6 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
return SDValue();
}
-/// See if the specified operand can be simplified with the knowledge that only
-/// the bits specified by DemandedBits are used.
-/// TODO: really we should be making this into the DAG equivalent of
-/// SimplifyMultipleUseDemandedBits and not generate any new nodes.
-SDValue SelectionDAG::GetDemandedBits(SDValue V, const APInt &DemandedBits) {
- EVT VT = V.getValueType();
-
- if (VT.isScalableVector())
- return SDValue();
-
- switch (V.getOpcode()) {
- default:
- return TLI->SimplifyMultipleUseDemandedBits(V, DemandedBits, *this);
- case ISD::Constant: {
- auto *C = cast<ConstantSDNode>(V);
- if (C->isOpaque())
- break;
- const APInt &CVal = C->getAPIntValue();
- APInt NewVal = CVal & DemandedBits;
- if (NewVal != CVal)
- return getConstant(NewVal, SDLoc(V), V.getValueType());
- break;
- }
- }
- return SDValue();
-}
-
/// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We
/// use this predicate to simplify operations downstream.
bool SelectionDAG::SignBitIsZero(SDValue Op, unsigned Depth) const {
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 11ad90faa7569..8f1e4d8247e15 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -649,7 +649,6 @@ bool TargetLowering::SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits,
AssumeSingleUse);
}
-// TODO: Can we merge SelectionDAG::GetDemandedBits into this?
// TODO: Under what circumstances can we create nodes? Constant folding?
SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
More information about the llvm-commits
mailing list