Skip to content

Commit ae2b6fb

Browse files
author
Dan Gohman
committed
Convert SimplifyDemandedMask and ShrinkDemandedConstant to use APInt.
Change several cases in SimplifyDemandedMask that don't ever do any simplifying to reuse the logic in ComputeMaskedBits instead of duplicating it. llvm-svn: 47648
1 parent bb7bc8d commit ae2b6fb

File tree

3 files changed

+156
-144
lines changed

3 files changed

+156
-144
lines changed

llvm/include/llvm/Target/TargetLowering.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ class TargetLowering {
610610
/// specified instruction is a constant integer. If so, check to see if
611611
/// there are any bits set in the constant that are not demanded. If so,
612612
/// shrink the constant and return true.
613-
bool ShrinkDemandedConstant(SDOperand Op, uint64_t Demanded);
613+
bool ShrinkDemandedConstant(SDOperand Op, const APInt &Demanded);
614614
};
615615

616616
/// SimplifyDemandedBits - Look at Op. At this point, we know that only the
@@ -621,8 +621,8 @@ class TargetLowering {
621621
/// KnownZero bits for the expression (used to simplify the caller).
622622
/// The KnownZero/One bits may only be accurate for those bits in the
623623
/// DemandedMask.
624-
bool SimplifyDemandedBits(SDOperand Op, uint64_t DemandedMask,
625-
uint64_t &KnownZero, uint64_t &KnownOne,
624+
bool SimplifyDemandedBits(SDOperand Op, const APInt &DemandedMask,
625+
APInt &KnownZero, APInt &KnownOne,
626626
TargetLoweringOpt &TLO, unsigned Depth = 0) const;
627627

628628
/// computeMaskedBitsForTargetNode - Determine which of the bits specified in

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ namespace {
118118
/// SimplifyDemandedBits - Check the specified integer node value to see if
119119
/// it can be simplified or if things it uses can be simplified by bit
120120
/// propagation. If so, return true.
121-
bool SimplifyDemandedBits(SDOperand Op, uint64_t Demanded = ~0ULL);
121+
bool SimplifyDemandedBits(SDOperand Op) {
122+
APInt Demanded = APInt::getAllOnesValue(Op.getValueSizeInBits());
123+
return SimplifyDemandedBits(Op, Demanded);
124+
}
125+
126+
bool SimplifyDemandedBits(SDOperand Op, const APInt &Demanded);
122127

123128
bool CombineToPreIndexedLoadStore(SDNode *N);
124129
bool CombineToPostIndexedLoadStore(SDNode *N);
@@ -534,10 +539,9 @@ SDOperand DAGCombiner::CombineTo(SDNode *N, const SDOperand *To, unsigned NumTo,
534539
/// SimplifyDemandedBits - Check the specified integer node value to see if
535540
/// it can be simplified or if things it uses can be simplified by bit
536541
/// propagation. If so, return true.
537-
bool DAGCombiner::SimplifyDemandedBits(SDOperand Op, uint64_t Demanded) {
542+
bool DAGCombiner::SimplifyDemandedBits(SDOperand Op, const APInt &Demanded) {
538543
TargetLowering::TargetLoweringOpt TLO(DAG, AfterLegalize);
539-
uint64_t KnownZero, KnownOne;
540-
Demanded &= MVT::getIntVTBitMask(Op.getValueType());
544+
APInt KnownZero, KnownOne;
541545
if (!TLI.SimplifyDemandedBits(Op, Demanded, KnownZero, KnownOne, TLO))
542546
return false;
543547

@@ -4501,7 +4505,10 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
45014505

45024506
// Otherwise, see if we can simplify the operation with
45034507
// SimplifyDemandedBits, which only works if the value has a single use.
4504-
if (SimplifyDemandedBits(Value, MVT::getIntVTBitMask(ST->getMemoryVT())))
4508+
if (SimplifyDemandedBits(Value,
4509+
APInt::getLowBitsSet(
4510+
Value.getValueSizeInBits(),
4511+
MVT::getSizeInBits(ST->getMemoryVT()))))
45054512
return SDOperand(N, 0);
45064513
}
45074514

0 commit comments

Comments
 (0)